-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workbox): enabled option and self destroying sw
- Loading branch information
Showing
7 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 file contains 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 file contains 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 file contains 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 file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// THIS FILE SHOULD NOT BE VERSION CONTROLLED | ||
|
||
// https://github.com/NekR/self-destroying-sw | ||
|
||
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 => client.navigate(client.url)) | ||
}) | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
if ('serviceWorker' in navigator) { | ||
navigator.serviceWorker.getRegistrations().then((registrations) => { | ||
for (const registration of registrations) { | ||
// Force update service worker for self-unregister | ||
registration.update() | ||
} | ||
}) | ||
} | ||
|
||
if ('caches' in window) { | ||
caches.keys() | ||
.then((keys) => { | ||
if (keys.length) { | ||
console.info('[pwa] [workbox] Cleaning cache for:', keys.join(', ')) | ||
for (const key of keys) { | ||
caches.delete(key) | ||
} | ||
} | ||
}) | ||
} |