Repository navigation
fix(hosting): serve the app shell with no-cache and stop rewriting missing scripts - #633
Conversation
…ssing scripts index.html was served with Firebase Hosting's default max-age=3600. After a deploy, a browser that had the page cached kept the previous entry bundle for up to an hour, while the chunks that bundle loads lazily were already gone. Every route change then failed with "Failed to fetch dynamically imported module" until a reload. Both hosting targets now send: - no-cache for the app shell and every other unhashed file, so the browser revalidates and picks up a deploy on the next navigation - one year, immutable, for content-hashed scripts and stylesheets - the previous one hour for fonts and images The SPA rewrite no longer answers a missing .js, .css or .map with index.html. A stale chunk request now gets a 404 instead of an HTML page with status 200.
There was a problem hiding this comment.
🔵 Needs a closer look
Changes to human-only firebase.json affect production caching and SPA routing for both hosting targets, requiring human sign-off on the protected-path exception and pending post-deployment validation.
No open issues 🎉
What changed in this PR
This PR updates Firebase Hosting cache and rewrite rules for both the player app and admin portal to reduce stale assets after deployments.
Changes:
- Revalidate app shells and unhashed files with
no-cache. - Cache content-hashed JavaScript and CSS for one year as immutable, while keeping the listed font and image formats on one-hour caching.
- Return
404for missing scripts, stylesheets, and source maps instead of rewriting them to the app shell.
| File | Description |
|---|---|
firebase.json |
Applies matching cache headers and SPA rewrite exclusions to both hosting targets. |
Review effort: Balanced
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review. Note You can configure setup steps for Copilot code review separately from Copilot cloud agent with a |
Problem
index.htmlis served with Firebase Hosting's defaultCache-Control: max-age=3600. After a deploy, a browser that has the page cached keeps loading the previous entry bundle for up to an hour. That bundle lazy-loads chunks by hash, and those files no longer exist after the deploy, so every route change fails:Seen on the production admin portal right after the Stride UI 2.x deploy: the open tab stayed on the old Angular 21 bundle and could not open any page until a reload. The request for the missing chunk came back as
200withtext/html, because the SPA rewrite answers every unknown path withindex.html.This applies to every deploy of both apps, not to that release in particular.
Change
firebase.jsononly, the same rules for theappandadmin-portalhosting targets.Cache-Control/, every route,index.htmlno-cachemax-age=3600ngsw.json,ngsw-worker.js,manifest.webmanifest,main.jsin the test buildno-cachemax-age=3600main-K3XR2YRG.js,chunk-_Wxkg63d.js,styles-PATJHLQI.css)public, max-age=31536000, immutablemax-age=3600max-age=3600no-cachemeans "revalidate before use", not "do not store": an unchanged shell is answered with a304.The SPA rewrite changes from
**to!**/*.@(js|css|map), so a missing script, stylesheet or source map gets a404instead of the app shell. Routes are unaffected.Not in this change
404on the next lazy route instead of a mislabelled HTML response, and a reload gets the new version at once. Prompting for that reload in the app (a chunk-load error handler, or the service worker's update event in the player app) is separate work.index.html, as before.no-cache, which is what removes the stale-bundle problem there.firebase.jsonis on the protected-paths list inAGENTS.md; this is a deliberate change to it.Test plan
Deployed the production build of the admin portal with these rules to a one-day preview channel on the test project and read the response headers:
/,/home,/users/123,/index.html→200,no-cachemain-*.js,chunk-*.js(including a hash with_),styles-*.css→public, max-age=31536000, immutablefavicon.ico→max-age=3600.cssand.map→404ngsw-worker.js,safety-worker.js,firebase-messaging-sw.js,worker-basic.min.jsstay onno-cache)