Skip to content

fix(ssr): serve the html entry with no-cache so deploys aren't frozen for a year - #742

Merged
tiberius0954 merged 1 commit into
masterfrom
fix/html-no-cache
Oct 15, 2026
Merged

tiberius0954 merged 1 commit into
masterfrom
fix/html-no-cache

Conversation

@tiberius0954

Copy link
Copy Markdown
Contributor

Problem

server.ts serves everything in /browser through express.static(..., { maxAge: "1y", index: "index.html" }). That 1-year cache is applied to the HTML entry document (index.html and the prerendered pages), not just the content-hashed assets. Because express.static serves index.html for a directory root even when it isn't requested by name, the root document / goes out with Cache-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

  • Keep maxAge: "1y" for hashed assets.
  • Send Cache-Control: no-cache for HTML: .html files served by express.static (via setHeaders) and the engine-rendered routes. no-cache still 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.

@snyk-io

snyk-io Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 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
tiberius0954 merged commit 4bf0d15 into master Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant