serve icon indicating copy to clipboard operation
serve copied to clipboard

Avoid rewriting non html resources to index.html on SPA (-s) option

Open danielzlotnik opened this issue 6 years ago • 0 comments

The problem

When having the fairly common combination of:

  • Hashed JS bundles build
  • Rolling update deployment (I.E k8s)
  • CDN caching

The following happens: image

  1. A client request reaches the new instance
  2. Serve responds with the the new build's index.html which references the new JS bundles.
  3. Client requests the new bundles from an old node.
  4. New bundles don't exist on the old node so serve (--single) responds with index.html instead.
  5. 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
  6. 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.

danielzlotnik avatar Jan 20 '20 11:01 danielzlotnik