Hub: add SW cleanup on load; add self-unregistering sw.js to kill stale Astro SW

This commit is contained in:
Davide Scaini
2026-05-03 18:47:30 +02:00
parent 8c10ff5574
commit 48ffc5be8e
2 changed files with 21 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', e => {
e.waitUntil((async () => {
await self.clients.claim();
const keys = await caches.keys();
await Promise.all(keys.map(k => caches.delete(k)));
const all = await self.clients.matchAll({ type: 'window', includeUncontrolled: true });
for (const c of all) c.navigate(c.url);
await self.registration.unregister();
})());
});