Skip to content

Instantly share code, notes, and snippets.

@scsskid
Last active December 16, 2020 13:40
Show Gist options
  • Save scsskid/14e0a334b8dcf0123c32c8dd8741abaf to your computer and use it in GitHub Desktop.
Save scsskid/14e0a334b8dcf0123c32c8dd8741abaf to your computer and use it in GitHub Desktop.
[ServiceWorker Delete Caches which arent in list] src: https://developers.google.com/web/fundamentals/primers/service-workers/#update-a-service-worker #serviceworker
self.addEventListener('activate', function(event) {
var cacheAllowlist = ['pages-cache-v1', 'blog-posts-cache-v1'];
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.map(function(cacheName) {
if (cacheAllowlist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment