feat: robust cache busting on deployment#33
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Conversation
- Express: Cache-Control no-cache/no-store/must-revalidate for index.html, sw.js, manifest.json; immutable 1yr cache for hashed assets - HTML: meta http-equiv tags to prevent browser caching of entry point - Service Worker: version-based cache purge on activate, notifies clients of version change, updateViaCache: none on registration - main.tsx: SW registration with update detection, 30min update polling, auto-reload on new version activation - APISIX: route-level cache headers — no-cache for /, /sw.js, /manifest.json; immutable 1yr for /assets/* Co-Authored-By: Patrick Munis <pmunis@gmail.com>
Contributor
Author
Original prompt from Patrick
|
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
Author
Test Results: Cache Busting on DeploymentTested by running a production-mode Express server (identical Cache Header Tests (5/5 passed)
Source Code Verification (5/5 passed)
Not Tested
|
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.
Summary
Prevents stale
index.html/ service worker from being served after deployment. Vite already content-hashes JS/CSS chunks, but the HTML shell and SW can get cached by the browser or APISIX gateway — causing users to load old bundles.Three-layer defense:
Express (server-side) —
serveStatic()and the SPA fallback now set:on
*.html,sw.js,manifest.json. Hashed assets (/assets/*) getmax-age=1y, immutable.Service Worker (client-side) — On
activate, the SW now purges all caches not matching the currentCACHE_VERSION, logs each purge, and postsSW_VERSION_CHANGEDto open clients.main.tsxregisters the SW withupdateViaCache: "none", pollsreg.update()every 30 min, and auto-reloads the page when a new SW activates.APISIX (gateway-level) — New routes for
/,/sw.js,/manifest.jsonwithresponse-rewritesetting no-cache headers./assets/*gets immutable 1yr cache.Also adds
<meta http-equiv="Cache-Control" ...>tags toindex.htmlas a belt-and-suspenders fallback for browsers that respect them.Link to Devin session: https://app.devin.ai/sessions/3ebd42bf0430422a9a2bd85ed9f9cd4c
Requested by: @munisp