fix: prevent stale HTML cache causing blank screen#667
Merged
Conversation
The Cache-Control: no-cache header in firebase.json only matched requests for /index.html, but the app uses hash history so the browser only requests /. Firebase served / with max-age=3600, causing the browser to cache HTML for up to 1 hour. After a new deployment the cached HTML referenced a bundle hash that no longer existed on the server, resulting in SyntaxError and a blank screen. Add no-cache header for / in firebase.json and add NetworkFirst strategy for navigation requests in the service worker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
Cache-Control: no-cacheheader infirebase.jsononly matched/index.html, but the app uses hash history so the browser only everrequests
/. Firebase served/with the defaultmax-age=3600,letting the browser cache the HTML for up to 1 hour. After a new
deployment the cached HTML referenced a bundle hash that no longer
existed, causing
SyntaxError: Unexpected token '<'and a blank screen.Verified: the live response for
/hadCache-Control: max-age=3600.Add
no-cachefor/infirebase.jsonso the browser always fetchesfresh HTML.
Add
NetworkFirstruntime caching for navigation requests in the serviceworker as defense-in-depth and offline fallback.
Test plan
npm test— 1686 tests passnpm run typecheck— cleannpm run build:prod— service worker output verified/response hasCache-Control: no-cache