From 37fa6d88b4727ee837615239acb954f5ec809dd4 Mon Sep 17 00:00:00 2001 From: soloturn Date: Wed, 11 Nov 2026 07:19:18 +0100 Subject: [PATCH] fix: ship a self-unregistering sw.js to retire the old Gatsby service worker Returning visitors still run the worker gatsby-plugin-offline installed and see the old site from its cache. /sw.js now 404s, which not every browser treats as an unregister. This one clears caches, unregisters and reloads open tabs. Co-Authored-By: soloturn --- public/sw.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 public/sw.js diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 00000000..9bae1f62 --- /dev/null +++ b/public/sw.js @@ -0,0 +1,15 @@ +// Retires the service worker the old Gatsby site installed in visitors' browsers. +// Safe to delete once old registrations have had months to expire. +self.addEventListener("install", () => self.skipWaiting()); + +self.addEventListener("activate", (event) => { + event.waitUntil( + (async () => { + for (const key of await caches.keys()) await caches.delete(key); + await self.registration.unregister(); + for (const client of await self.clients.matchAll({ type: "window" })) { + client.navigate(client.url); + } + })(), + ); +});