Created
July 26, 2020 19:42
-
-
Save Himachallad/8bfac63d24b9cffc67b47699198b13ac to your computer and use it in GitHub Desktop.
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
| /** | |
| * Activates the new service worker and clean old cache incase of version changes | |
| */ | |
| self.addEventListener("activate", (event) => { | |
| const currentCaches = [UNVARYING_CACHE, VOLATILE]; | |
| event.waitUntil( | |
| caches | |
| .keys() | |
| .then((cacheNames) => { | |
| return cacheNames.filter( | |
| (cacheName) => !currentCaches.includes(cacheName) | |
| ); | |
| }) | |
| .then((cachesToDelete) => { | |
| return Promise.all( | |
| cachesToDelete.map((cacheToDelete) => { | |
| return caches.delete(cacheToDelete); | |
| }) | |
| ); | |
| }) | |
| .then(() => self.clients.claim()) | |
| ); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment