serve
serve copied to clipboard
Avoid rewriting non html resources to index.html on SPA (-s) option
The problem
When having the fairly common combination of:
- Hashed JS bundles build
- Rolling update deployment (I.E k8s)
- CDN caching
The following happens:

- A client request reaches the new instance
- Serve responds with the the new build's
index.htmlwhich references the new JS bundles. - Client requests the new bundles from an old node.
- New bundles don't exist on the old node so serve (--single) responds with
index.htmlinstead. - Browser trying to execute html as JS which breaks the rendering of the page:
refused to execute script from ... because its mime type ('text/html') is not executable - CDN caches this seemingly valid 200 response, all following requests will return HTML instead of JS as well until purged / expired.
Possible solution
I could not find any existing option or configuration which solves the above issue so if there is one - please let me know.
Either-way I think the -s option should by default exclude certain (or maybe all non-html) file extensions (js, css, jpg, etc...) before rewriting the response as index.html.