18c4530721
Per Codex + Jay: the SW was added for nice-to-have PWA/offline caching, but it sat in the boot path and put first loads at risk (post-deploy tiny-chunk stalls of 4-10s — fast HTML, then delayed chunks). For a young site where a handful of visitors a day IS the audience, a broken first impression is a huge share of traffic. The site's value doesn't need offline caching; browser HTTP cache + the Cloudflare edge are enough. Removed cleanly (not just deleted — that strands the old worker on existing clients): - Delete src/service-worker.js → SvelteKit stops auto-registering. - static/service-worker.js is now a one-shot KILL SWITCH: takes over, wipes all caches, unregisters itself, no fetch handler (requests go straight to network/ browser cache). Served no-cache so existing clients pick it up. - app.html boot script unregisters any worker + clears caches on load, as a backstop so no returning visitor stays stuck on the old boot path. The boot seatbelt (timeout card, preloadError reload-once, telemetry) stays — that, not the SW, was the real blank-screen protection. Build clean, 11 vitest. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
// Kill switch — the app no longer uses a service worker.
|
|
//
|
|
// It was added for nice-to-have PWA/offline caching, but it sat in the boot
|
|
// path and put first loads at risk (post-deploy chunk stalls), which a young
|
|
// site with few visitors can't afford. Browser HTTP cache + the Cloudflare edge
|
|
// are enough for a news site.
|
|
//
|
|
// Existing visitors still have the OLD worker registered and controlling their
|
|
// pages. This replacement (served at /service-worker.js, no-cache) takes over,
|
|
// wipes the old caches, and unregisters itself. There is deliberately NO fetch
|
|
// handler, so every request goes straight to the network / browser HTTP cache.
|
|
// The app also unregisters any worker on load (see app.html) as a backstop.
|
|
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 (e) {
|
|
/* best effort */
|
|
}
|
|
try {
|
|
await self.registration.unregister();
|
|
} catch (e) {
|
|
/* best effort */
|
|
}
|
|
})()
|
|
);
|
|
});
|