Skip to content

feat: robust cache busting on deployment#3

Open
devin-ai-integration[bot] wants to merge 1 commit into
developmentfrom
devin/1781874520-cache-busting
Open

feat: robust cache busting on deployment#3
devin-ai-integration[bot] wants to merge 1 commit into
developmentfrom
devin/1781874520-cache-busting

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Vite already content-hashes JS/CSS chunks, but index.html can be cached by the browser or APISIX — causing users to load stale entry points that reference old chunk filenames. This PR adds 6 layers of cache busting to guarantee users always get fresh code on deploy:

Layer 1 — HTML <meta> tags (all 3 index.html)

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

Layer 2 — nginx configs (new for web2 + tenant_admin, updated for 54link_admin)

location = /index.html { add_header Cache-Control "no-cache, no-store, must-revalidate"; }
location /assets/       { expires 1y; add_header Cache-Control "public, immutable"; }
location = /sw.js       { add_header Cache-Control "no-cache, no-store, must-revalidate"; }

Layer 3 — APISIX response-rewrite plugin (3 web app routes)

Priority routing: /assets/* (p20, immutable) > /sw.js (p15, no-cache) > /* (p10, no-cache for HTML).

Layer 4 — Service worker version-based cache purge

CACHE_VERSION is stamped at build time by a Vite plugin. On activate, the SW deletes all caches not matching the current version and posts SW_UPDATED to all open tabs.

Layer 5 — Client-side SW registration

  • updateViaCache: 'none' on register() — bypasses HTTP cache for sw.js
  • 60s polling via registration.update()
  • controllerchange auto-reloads the page
  • Non-intrusive "new version available" banner with Reload/Later buttons

Layer 6 — Vite build config

Explicit assets/[name]-[hash].js output + swVersionStamp() plugin that writes a unique MD5 hash into dist/sw.js at closeBundle.

Also

  • web2 and tenant_admin Dockerfiles upgraded from dev mode (npm run dev) to production builds (multi-stage → nginx).

Link to Devin session: https://app.devin.ai/sessions/07858e6781a543618f2cdd22ec11ac24
Requested by: @munisp

Layer 1 — HTML meta tags (all 3 index.html files):
  Cache-Control: no-cache, no-store, must-revalidate
  Pragma: no-cache / Expires: 0

Layer 2 — nginx configs (all 3 UIs):
  index.html + SPA fallback: no-cache, no-store, must-revalidate
  /assets/*: public, immutable (1 year) — Vite content-hashed filenames
  /sw.js: no-cache, no-store — forces browser to detect new SW
  /manifest.json: no-cache, must-revalidate

Layer 3 — APISIX gateway (3 web app routes):
  response-rewrite plugin injects Cache-Control headers
  /assets/* priority 20: immutable (hashed by Vite)
  /sw.js priority 15: no-cache
  /* priority 10: no-cache for HTML

Layer 4 — Service worker version-based cache clearing:
  CACHE_VERSION stamped by Vite build plugin (sw-version-stamp)
  activate handler purges ALL caches not matching current version
  SW_UPDATED message notifies open tabs
  Client shows 'new version available' banner with reload button

Layer 5 — Client-side SW registration:
  updateViaCache: 'none' — bypass HTTP cache for sw.js fetch
  Periodic update check every 60s
  controllerchange listener auto-reloads on SW takeover

Layer 6 — Vite build config:
  Explicit content-hash filenames: assets/[name]-[hash].js
  swVersionStamp plugin writes unique hash into dist/sw.js

Also: production Dockerfiles for web2 + tenant_admin (were running dev mode)
Co-Authored-By: Patrick Munis <pmunis@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author
Original prompt from Patrick

https://drive.google.com/file/d/1LE3Fw1DBgwl-3Aj7Bq3h-k7Xyo3tDt3i/view?usp=sharing
Extract ALL, analyze and refactor the core banking platform. Perform gap analysis and production readies. Identifty stubs, mocks, and placeholders

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

0 participants