Skip to content

Instantly share code, notes, and snippets.

@x1unix
Created July 15, 2024 13:29
Show Gist options
  • Save x1unix/9360dd5c118d52bca49c8f83f90ded89 to your computer and use it in GitHub Desktop.
Save x1unix/9360dd5c118d52bca49c8f83f90ded89 to your computer and use it in GitHub Desktop.
self-destruct SW
// Self-destructible service worker stub
self.addEventListener('install', function(e) {
self.skipWaiting();
})
self.addEventListener('activate', function(e) {
self.registration.unregister()
.then(function () {
return self.clients.matchAll();
})
.then(function (clients) {
clients.forEach(client => {
if (client instanceof WindowClient) {
client.navigate(client.url)
}
})
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment