Fix SPA cache headers so deploys do not strand stale index.html#89
Open
Gorfaal wants to merge 1 commit into
Open
Fix SPA cache headers so deploys do not strand stale index.html#89Gorfaal wants to merge 1 commit into
Gorfaal wants to merge 1 commit into
Conversation
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>
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.
Port of qanat#894.
After the SPA fallback rewrites a 404 to
/index.html, also setResponse.StatusCode = 200so the SPA shell is delivered cleanly. ConfigureUseStaticFileswith anOnPrepareResponsecallback that setsCache-Control: public, max-age=31536000, immutableon hashed bundles andCache-Control: no-cacheon everything else (notablyindex.html), so a client that already cached the previous deploy'sindex.htmlre-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.Webpreserved (legacy). Combined regex's webpack alternative covers OregonTilth's lowercase-hex hashes.Test plan
index.htmlreturnsCache-Control: no-cacheCache-Control: public, max-age=31536000, immutable🤖 Generated with Claude Code