Skip to content

Instantly share code, notes, and snippets.

@pugson
Created May 11, 2020 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pugson/8f637ce5d885dcea9ff6c0ae3ff5fc20 to your computer and use it in GitHub Desktop.
Save pugson/8f637ce5d885dcea9ff6c0ae3ff5fc20 to your computer and use it in GitHub Desktop.
nuke your old service worker
// This is a worker that can be deployed in a desperate situation in order
// to disable all service worker caching by overwriting the running worker
// with a no-op worker.
//
// Keep it close for when you need it.
self.addEventListener("install", () => {
// Activate immediately, taking control from any broken service workers
self.skipWaiting();
});
self.addEventListener("activate", () => {
// Get a list of all the current open windows/tabs under
// our service worker's control, and force them to reload.
// This can "unbreak" any open windows/tabs as soon as the new
// service worker activates, rather than users having to manually reload.
self.clients.matchAll({ type: "window" }).then(clients => {
clients.forEach(windowClient => windowClient.navigate(windowClient.url));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment