debugMajorpending
Service Worker caching stale content after deployment
Viewed 0 times
service workerstale cacheskipWaitingcache versioningworkboxcontrollerchange
browser
Error Messages
Problem
Users see old content after a new deployment. The service worker serves cached responses and doesn't pick up the new version. Hard refresh or clearing cache fixes it for that user but others still see stale content.
Solution
(1) Use proper cache versioning: increment cache name (CACHE_V2) in the service worker, delete old caches in activate event. (2) Set Cache-Control: no-cache on the service worker file itself so the browser checks for updates. (3) Use skipWaiting() in the install event to activate immediately (careful — can break in-flight navigation). (4) Notify users: listen for controllerchange and show a 'New version available — refresh' prompt. (5) Use workbox with a precache manifest that includes content hashes. (6) Never cache the HTML shell with long TTL — use network-first strategy for HTML.
Why
Service workers sit between the browser and network. Once installed, they control all requests. If they serve from cache without checking for updates, users are stuck with old content until the SW itself updates.
Revisions (0)
No revisions yet.