Created
May 11, 2020 18:17
-
-
Save pugson/8f637ce5d885dcea9ff6c0ae3ff5fc20 to your computer and use it in GitHub Desktop.
nuke your old service worker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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