Skip to content

fix: prevent service worker from caching stale HTML#1060

Merged
koala73 merged 3 commits intomainfrom
worktree-declarative-gliding-bird
Mar 5, 2026
Merged

fix: prevent service worker from caching stale HTML#1060
koala73 merged 3 commits intomainfrom
worktree-declarative-gliding-bird

Conversation

@koala73
Copy link
Owner

@koala73 koala73 commented Mar 5, 2026

Summary

Users are getting 404 errors on bundle files after deploys because the service worker's NetworkFirst handler with a 3-second timeout falls back to stale cached HTML that references old content-hashed bundles.

Changes

  • vite.config.ts: Change navigation handler from NetworkFirst (3s timeout) → NetworkOnly — HTML always comes from network
  • src/main.ts: Reduce SW update check from 60min → 5min for faster deploy propagation

Why this fixes it

The SW precaches all .js files via globPatterns. On deploy, new hashes are generated. Until the SW updates its manifest, it serves the old HTML which references old bundle hashes → 404. NetworkOnly for navigation ensures HTML is never served from SW cache.

Test plan

  • Deploy, then hard-refresh — no 404s
  • Check SW fetch events in DevTools Network tab — navigation requests should show "(ServiceWorker)" with NetworkOnly strategy
  • Offline: navigation will show offline.html fallback (no change from before — navigateFallback: null)

koala73 added 3 commits March 5, 2026 14:31
- Increase polling intervals (markets 8→12min, feeds 15→20min, crypto 8→12min)
- Increase background tab hiddenMultiplier from 10→30 (polls 3x less when hidden)
- Double CDN s-maxage TTLs across all cache tiers in gateway
- Add CDN-Cache-Control header for Cloudflare-specific longer edge caching
- Add ETag generation + 304 Not Modified support in gateway (zero-byte revalidation)
- Add CDN-Cache-Control to bootstrap endpoint
- Add explicit SPA rewrite rule in vercel.json for CF proxy compatibility
- Add Cache-Control headers for /map-styles/, /data/, /textures/ static paths
- vercel.json: apply no-cache headers to ALL SPA routes (same regex as
  rewrite rule), not just / and /index.html — prevents CF proxy from
  caching stale HTML that references old content-hashed bundle filenames
- Polymarket: add server-side aggregation via Railway seed script that
  fetches all tags once and writes to Redis, eliminating 11-request
  fan-out per user per poll cycle
- Bootstrap: add predictions to hydration keys for zero-cost page load
- RPC handler: read Railway-seeded bootstrap key before falling back to
  live Gamma API fetch
- Client: 3-strategy waterfall (bootstrap → RPC → fan-out fallback)
- Change navigation handler from NetworkFirst (3s timeout) to NetworkOnly
  so HTML always comes from the network, never from stale SW cache
- Reduce SW update check interval from 60min to 5min so new deploys
  propagate to users faster
- Root cause: SW precached all .js files, and NetworkFirst with 3s timeout
  would fall back to stale cached HTML referencing old content-hashed
  bundles that no longer exist after deploy → 404
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vercel
Copy link

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worldmonitor Building Building Preview, Comment Mar 5, 2026 0:52am

Request Review

@koala73 koala73 merged commit 9384bdb into main Mar 5, 2026
2 of 3 checks passed
koala73 added a commit that referenced this pull request Mar 5, 2026
Users with stale service workers get 404s on content-hashed bundles.
The deployed sw.js has skipWaiting+clientsClaim but old SWs from before
PR #1060 don't self-update reliably. This adds a one-time nuke in main.ts
that unregisters all SWs, clears all caches, and reloads. Guarded by
localStorage key so it only fires once per browser. Safe to remove after
2026-03-20.
koala73 added a commit that referenced this pull request Mar 5, 2026
Users with stale service workers get 404s on content-hashed bundles.
The deployed sw.js has skipWaiting+clientsClaim but old SWs from before
PR #1060 don't self-update reliably. This adds a one-time nuke in main.ts
that unregisters all SWs, clears all caches, and reloads. Guarded by
localStorage key so it only fires once per browser. Safe to remove after
2026-03-20.
koala73 added a commit that referenced this pull request Mar 5, 2026
Users with stale service workers get 404s on content-hashed bundles.
The deployed sw.js has skipWaiting+clientsClaim but old SWs from before
PR #1060 don't self-update reliably. This adds a one-time nuke in main.ts
that unregisters all SWs, clears all caches, and reloads. Guarded by
localStorage key so it only fires once per browser. Safe to remove after
2026-03-20.
aldoyh pushed a commit to aldoyh/worldmonitor that referenced this pull request Mar 6, 2026
* perf: reduce Vercel data transfer costs with CDN optimization

- Increase polling intervals (markets 8→12min, feeds 15→20min, crypto 8→12min)
- Increase background tab hiddenMultiplier from 10→30 (polls 3x less when hidden)
- Double CDN s-maxage TTLs across all cache tiers in gateway
- Add CDN-Cache-Control header for Cloudflare-specific longer edge caching
- Add ETag generation + 304 Not Modified support in gateway (zero-byte revalidation)
- Add CDN-Cache-Control to bootstrap endpoint
- Add explicit SPA rewrite rule in vercel.json for CF proxy compatibility
- Add Cache-Control headers for /map-styles/, /data/, /textures/ static paths

* fix: prevent CF from caching SPA HTML + reduce Polymarket bandwidth 95%

- vercel.json: apply no-cache headers to ALL SPA routes (same regex as
  rewrite rule), not just / and /index.html — prevents CF proxy from
  caching stale HTML that references old content-hashed bundle filenames
- Polymarket: add server-side aggregation via Railway seed script that
  fetches all tags once and writes to Redis, eliminating 11-request
  fan-out per user per poll cycle
- Bootstrap: add predictions to hydration keys for zero-cost page load
- RPC handler: read Railway-seeded bootstrap key before falling back to
  live Gamma API fetch
- Client: 3-strategy waterfall (bootstrap → RPC → fan-out fallback)

* fix: prevent service worker from serving stale HTML after deploys

- Change navigation handler from NetworkFirst (3s timeout) to NetworkOnly
  so HTML always comes from the network, never from stale SW cache
- Reduce SW update check interval from 60min to 5min so new deploys
  propagate to users faster
- Root cause: SW precached all .js files, and NetworkFirst with 3s timeout
  would fall back to stale cached HTML referencing old content-hashed
  bundles that no longer exist after deploy → 404
aldoyh pushed a commit to aldoyh/worldmonitor that referenced this pull request Mar 6, 2026
Users with stale service workers get 404s on content-hashed bundles.
The deployed sw.js has skipWaiting+clientsClaim but old SWs from before
PR koala73#1060 don't self-update reliably. This adds a one-time nuke in main.ts
that unregisters all SWs, clears all caches, and reloads. Guarded by
localStorage key so it only fires once per browser. Safe to remove after
2026-03-20.
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