Skip to content

fix(hosting): serve the app shell with no-cache and stop rewriting missing scripts - #633

Merged
mschilling merged 1 commit into
mainfrom
fix/hosting-index-no-cache
Nov 27, 2026
Merged

mschilling merged 1 commit into
mainfrom
fix/hosting-index-no-cache

Conversation

@mschilling

@mschilling mschilling commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

index.html is served with Firebase Hosting's default Cache-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:

ERROR TypeError: Failed to fetch dynamically imported module: https://admin.codeheroes.app/chunk-Y2TMPYNP.js

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 200 with text/html, because the SPA rewrite answers every unknown path with index.html.

This applies to every deploy of both apps, not to that release in particular.

Change

firebase.json only, the same rules for the app and admin-portal hosting targets.

Path Cache-Control Was
App shell: /, every route, index.html no-cache max-age=3600
Other unhashed files: ngsw.json, ngsw-worker.js, manifest.webmanifest, main.js in the test build no-cache max-age=3600
Content-hashed scripts and stylesheets (main-K3XR2YRG.js, chunk-_Wxkg63d.js, styles-PATJHLQI.css) public, max-age=31536000, immutable max-age=3600
Fonts and images max-age=3600 unchanged

no-cache means "revalidate before use", not "do not store": an unchanged shell is answered with a 304.

The SPA rewrite changes from ** to !**/*.@(js|css|map), so a missing script, stylesheet or source map gets a 404 instead of the app shell. Routes are unaffected.

Not in this change

  • An app that is already open still holds the old bundle in memory. It now fails with a real 404 on 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.
  • A missing image or font is still rewritten to index.html, as before.
  • The test build has no output hashing for its entry files (Enable output hashing for Angular build assets #379). They now get no-cache, which is what removes the stale-bundle problem there.

firebase.json is on the protected-paths list in AGENTS.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-cache
  • main-*.js, chunk-*.js (including a hash with _), styles-*.css → public, max-age=31536000, immutable
  • a font, an icon, favicon.ico → max-age=3600
  • a chunk name that does not exist, a missing .css and .map → 404
  • Production build of the player app: no unhashed script matches the immutable pattern (ngsw-worker.js, safety-worker.js, firebase-messaging-sw.js, worker-basic.min.js stay on no-cache)
  • CI green on this PR
  • After the next deploy of each app: an already-cached tab picks up the new version on a normal navigation

…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.
@mschilling mschilling added the bug Something isn't working label Nov 27, 2026
Copilot AI balanced review requested due to automatic review settings November 27, 2026 19:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 404 for 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

Copilot AI commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Install node modules

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 copilot-code-review.yml file. Read the docs for details.

@mschilling
mschilling merged commit 6c30453 into main Nov 27, 2026
1 of 2 checks passed
@mschilling
mschilling deleted the fix/hosting-index-no-cache branch November 27, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants