feat(collab): immutable cache headers on content-hashed static assets#44
Merged
Conversation
Speed win V4 — repeat-visit + SPA-reload polish. The collab SPA's hashed assets (Vite emits /assets/* and <name>-<hash>.<ext>) were served with whatever default cache headers the upstream UI route sets, so every reload re-fetched them. collabMiddleware now stamps `Cache-Control: public, max-age=31536000, immutable` on GET responses for content-hashed assets — matched by the /assets/ prefix OR a `-<hash>.<ext>` filename pattern across the usual static extensions (js/css/fonts/images/wasm/map). The header is added only on 2xx (never cache a 404), and ONLY in the collab middleware so upstream opencode's own asset serving is untouched. index.html and other un-hashed paths are deliberately excluded, so a deploy's fresh asset manifest is always picked up — the hashed filenames guarantee cache-busting on content change. Co-Authored-By: Claude Opus 4.8 (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.
Speed win V4 (PR 5 of 5) — repeat-visit + SPA-reload polish.
What
The collab SPA's hashed assets (Vite emits
/assets/*and<name>-<hash>.<ext>) were served with the upstream UI route's default cache headers, so every reload re-fetched them.collabMiddlewarenow stampsCache-Control: public, max-age=31536000, immutableon GET responses for content-hashed assets:/assets/prefix or a-<hash>.<ext>filename pattern across the usual static extensions (js/css/fonts/images/wasm/map)index.htmland other un-hashed paths are deliberately excluded, so a deploy's fresh asset manifest is always picked up — the hashed filenames guarantee cache-busting on content change.Uses
HttpServerResponse.setHeader, the same API the existing compression / fence / cors-vary middlewares use.Files
server/server.ts—isHashedStaticAsset()matcher + header stamp incollabMiddlewareTest plan
/collab/new, open DevTools → Network → reload/assets/index-XXXX.js, etc.) showCache-Control: public, max-age=31536000, immutableand serve from disk cache on reloadindex.html(the navigation request) is NOT immutable-cached — a fresh deploy's new asset hashes load without a hard refresh/assets/missing-1234abcd.jsdoes NOT get the immutable header🤖 Generated with Claude Code