Skip to content

Fix SPA cache headers so deploys do not strand stale index.html#89

Open
Gorfaal wants to merge 1 commit into
developfrom
bugfix/spa-cache-headers
Open

Fix SPA cache headers so deploys do not strand stale index.html#89
Gorfaal wants to merge 1 commit into
developfrom
bugfix/spa-cache-headers

Conversation

@Gorfaal
Copy link
Copy Markdown

@Gorfaal Gorfaal commented May 4, 2026

Port of qanat#894.

After the SPA fallback rewrites a 404 to /index.html, also set Response.StatusCode = 200 so the SPA shell is delivered cleanly. Configure UseStaticFiles with an OnPrepareResponse callback that sets Cache-Control: public, max-age=31536000, immutable on hashed bundles and Cache-Control: no-cache on everything else (notably index.html), so a client that already cached the previous deploy's index.html re-fetches on the next page load instead of trying to load deleted hashed chunks.

The combined regex (?:-[A-Z0-9]{8,}|\.[a-f0-9]{16,})\.[a-z0-9]+$ matches both Angular esbuild's uppercase base32 hashes and the classic webpack builder's lowercase hex hashes — verified against real bundle filenames from across esassoc apps.

Drift from qanat: Namespace Fresca.Web preserved (legacy). Combined regex's webpack alternative covers OregonTilth's lowercase-hex hashes.

Test plan

  • Deploy to QA, hard-refresh browser, confirm index.html returns Cache-Control: no-cache
  • Confirm hashed bundles return Cache-Control: public, max-age=31536000, immutable
  • Confirm a deep SPA route loads with HTTP 200 not 404

🤖 Generated with Claude Code

Port of qanat bugfix/spa-cache-headers to OregonTilth.Web. After the
SPA fallback rewrites a 404 to /index.html, also set the response
status to 200 so the SPA shell is delivered cleanly. Configure
UseStaticFiles with an OnPrepareResponse callback that gives hashed
bundles immutable long-cache and everything else (notably index.html)
no-cache, so a client that already cached the previous deploy''s
index.html re-fetches on the next page load instead of trying to
load deleted hashed chunks.

OregonTilth uses the classic webpack builder (lowercase-hex hashes);
the combined regex includes that branch.

Source: esassoc/qanat#894 (branch bugfix/spa-cache-headers).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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