Summary
New SW waits in waiting until tabs close — users stuck on old cache. skipWaiting + clients.claim() forces update but can mid-session break. Version caches explicitly; delete old caches on activate. Scope limited to path — wrong registration path = no control. Auth tokens in SW cache = risk.
Code example
self.addEventListener('install', (event) => {
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(keys.filter((k) => k !== CACHE_VERSION).map((k) => caches.delete(k)))
)
);
clients.claim();
});
Key points
- New SW waits in
waitinguntil tabs close — users stuck on old cache. skipWaiting+clients.claim()forces update but can mid-session break.- Version caches explicitly; delete old caches on activate.
- Scope limited to path — wrong registration path = no control.
- Auth tokens in SW cache = risk.