Remove the service worker (protect first loads)
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>
This commit is contained in:
@@ -38,6 +38,19 @@
|
||||
// screen. Show a calm recovery card if the app hasn't mounted, and reload
|
||||
// once on a chunk/preload failure (e.g. a just-deployed hashed chunk).
|
||||
(function () {
|
||||
// The service worker was removed (it risked first loads). Actively
|
||||
// unregister any worker a returning visitor still has + wipe its caches,
|
||||
// so nobody stays stuck on the old boot path. Runs on every load; cheap.
|
||||
if ('serviceWorker' in navigator) {
|
||||
try {
|
||||
navigator.serviceWorker.getRegistrations()
|
||||
.then(function (rs) { rs.forEach(function (r) { r.unregister(); }); })
|
||||
.catch(function () {});
|
||||
if (self.caches && caches.keys) {
|
||||
caches.keys().then(function (ks) { ks.forEach(function (k) { caches.delete(k); }); }).catch(function () {});
|
||||
}
|
||||
} catch (e) { /* best effort */ }
|
||||
}
|
||||
var sent = false;
|
||||
function report(reason) {
|
||||
if (sent) return; sent = true; // one beacon per page
|
||||
|
||||
Reference in New Issue
Block a user