31 lines
1.4 KiB
JavaScript
31 lines
1.4 KiB
JavaScript
// Self-unregistering "tombstone" service worker.
|
|
//
|
|
// Void 1 ran at this same origin (void.hynesy.com) and registered a caching
|
|
// service worker at /sw.js. Void 2 ships NO service worker, so that old worker
|
|
// would otherwise persist forever in returning visitors' browsers, intercepting
|
|
// fetches and serving stale assets that even a hard reload cannot bypass.
|
|
//
|
|
// Serving this self-destructing worker at the same /sw.js URL means the browser's
|
|
// periodic SW update check (which bypasses the HTTP cache and is not intercepted
|
|
// by the old worker) replaces the old worker with this one. On activation it
|
|
// wipes every cache, unregisters itself, and reloads open tabs — after which the
|
|
// page loads fresh from the network with no controlling service worker.
|
|
//
|
|
// Keep serving this indefinitely so any device that ever ran Void 1 self-heals.
|
|
|
|
self.addEventListener('install', () => self.skipWaiting());
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil((async () => {
|
|
try {
|
|
const keys = await caches.keys();
|
|
await Promise.all(keys.map((k) => caches.delete(k)));
|
|
} catch (_) { /* best effort */ }
|
|
try { await self.registration.unregister(); } catch (_) { /* best effort */ }
|
|
const clients = await self.clients.matchAll({ type: 'window' });
|
|
for (const client of clients) {
|
|
try { client.navigate(client.url); } catch (_) { /* best effort */ }
|
|
}
|
|
})());
|
|
});
|