Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: SPA should 404 on fetching obvious non-html assets #257

Closed
transitive-bullshit opened this issue Aug 16, 2017 · 4 comments
Closed

Comments

@transitive-bullshit
Copy link

For SPAs, a common issue I've run into is that as hashed static resources change between deployments, a stale client requests an old asset (oftentimes due to a client-side service worker), and failing to find the static resource, serve naively returns index.html which is almost never what you want and leads to weird client-side errors.

See here and here for solid descriptions of the general problem aside from serve.

I realize this is how most static file serving solutions work, but I know we can do better for the majority use case, where the requested resource is in a blacklist of common content-types (e.g., js, css, png, jpg, svg, etc).

I'd like to propose adding an optional flag to augment SPA mode whereby these types of resource requests return 404 if not found, instead of naively returning index.html.

Thoughts?

@sergiodxa
Copy link

In a SPA your 404 is usually being rendered client side, that means you need to first get your index.html, start your app and then check the URL to render your app or render a 404.

@transitive-bullshit
Copy link
Author

@sergiodxa the whole point here is that the server isn't returning a 404 -- it's returning index.html for a missing static asset as opposed to returning a 404 which could be gracefully handled client-side.

@leo
Copy link
Contributor

leo commented May 28, 2018

Thank you for the effort you've put into this!

This is now possible by supplying a serve.json file. All thanks to serve-handler, as described in the notes for the new release.

Simply add headers to your config file, as described in the serve-handler documentation.

@leo leo closed this as completed May 28, 2018
@minhdao88
Copy link

Sorry to bother but I just stumbled upon this issue recently, and after checked serve-handler documentation I still don't understand how to config it to return 404 status instead of the HTML file.

Any help would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants