From aca83c9b8da03722f100e942fe65535d966998f9 Mon Sep 17 00:00:00 2001 From: Michael Schilling Date: Fri, 27 Nov 2026 20:32:21 +0100 Subject: [PATCH] fix(hosting): serve the app shell with no-cache and stop rewriting missing 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. --- firebase.json | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/firebase.json b/firebase.json index 39362f55..0af7759d 100644 --- a/firebase.json +++ b/firebase.json @@ -12,9 +12,38 @@ "**/.*", "**/node_modules/**" ], - "rewrites": [ + "headers": [ { "source": "**", + "headers": [ + { + "key": "Cache-Control", + "value": "no-cache" + } + ] + }, + { + "source": "**/*.@(woff2|woff|svg|png|jpg|jpeg|webp|ico)", + "headers": [ + { + "key": "Cache-Control", + "value": "max-age=3600" + } + ] + }, + { + "regex": "^/.+-[A-Za-z0-9_-]{8}\\.(js|css)$", + "headers": [ + { + "key": "Cache-Control", + "value": "public, max-age=31536000, immutable" + } + ] + } + ], + "rewrites": [ + { + "source": "!**/*.@(js|css|map)", "destination": "/index.html" } ] @@ -27,9 +56,38 @@ "**/.*", "**/node_modules/**" ], - "rewrites": [ + "headers": [ { "source": "**", + "headers": [ + { + "key": "Cache-Control", + "value": "no-cache" + } + ] + }, + { + "source": "**/*.@(woff2|woff|svg|png|jpg|jpeg|webp|ico)", + "headers": [ + { + "key": "Cache-Control", + "value": "max-age=3600" + } + ] + }, + { + "regex": "^/.+-[A-Za-z0-9_-]{8}\\.(js|css)$", + "headers": [ + { + "key": "Cache-Control", + "value": "public, max-age=31536000, immutable" + } + ] + } + ], + "rewrites": [ + { + "source": "!**/*.@(js|css|map)", "destination": "/index.html" } ]