Repository navigation
fix(ssr): serve the html entry with no-cache so deploys aren't frozen for a year - #742
Merged
Merged
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
… for a year express.static applied maxAge 1y to index.html and the prerendered pages, not just the hashed assets. Browsers and the CDN then cache the entry document for a year, pinning users to an old build (with its old asset hashes) after every release until the cache is manually purged. Keep the 1y cache on hashed assets, but send Cache-Control: no-cache for HTML so the entry revalidates.
tiberius0954
force-pushed
the
fix/html-no-cache
branch
from
October 15, 2026 21:07
beab06e to
73152b6
Compare
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.
Problem
server.tsserves everything in/browserthroughexpress.static(..., { maxAge: "1y", index: "index.html" }). That 1-year cache is applied to the HTML entry document (index.htmland the prerendered pages), not just the content-hashed assets. Becauseexpress.staticservesindex.htmlfor a directory root even when it isn't requested by name, the root document/goes out withCache-Control: public, max-age=31536000.Browsers and the CDN (Fastly) then freeze that HTML for a year. Since the HTML hard-codes the hashed asset filenames (
styles-<hash>.css,main-<hash>.js), a frozen entry document pins visitors to an entire old build after every deploy — the new build is live on the origin, but cached/keeps pointing at the previous build's assets until the cache is manually purged. Hashed assets are unaffected (their filename changes each build), so only the unhashed HTML entry needs to revalidate.Change
maxAge: "1y"for hashed assets.Cache-Control: no-cachefor HTML:.htmlfiles served byexpress.static(viasetHeaders) and the engine-rendered routes.no-cachestill allows storage and conditional revalidation (304s), it just forces the entry document to be checked against the origin so a new deploy is picked up immediately.Note
This stops future deploys from freezing. The copy already cached at the CDN from before this change still needs a one-time purge to clear.