angular / mobile-toolkit

Tools for building progressive web apps with Angular
MIT License
1.34k stars 175 forks source link

fix(worker): manually follow redirects in static content caching #148

Closed alxhub closed 7 years ago

alxhub commented 7 years ago

Before this change, static content caching would fetch all the URLs described in the manifest directly, and accept whatever response came back.

If, though, a server was configured to redirect one of the static URLs (for example, Firebase 301 redirects /index.html to /), the response would be cached as a 200 with the Response.redirected flag set to true. It is illegal per the SW spec to respond to a navigation request with such a redirected Response, and this breaks in Chrome 59 and higher.

With this change, static content caching now looks at Response.redirected and if the flag is set, it requests Response.url directly to obtain a Response which was not redirected.

An e2e test verifies that such a redirected static URL still works as a navigation request.