Skip to content

Instantly share code, notes, and snippets.

@ankitamasand
Last active October 31, 2018 19:35
Show Gist options
  • Save ankitamasand/346b7c29515ff316180f8f7c2683bbaa to your computer and use it in GitHub Desktop.
Save ankitamasand/346b7c29515ff316180f8f7c2683bbaa to your computer and use it in GitHub Desktop.
self.addEventListener('activate', (event) => {
let cacheWhitelist = ['products-v2'] // products-v2 is the name of the new cache
event.waitUntil(
caches.keys().then (cacheNames => {
return Promise.all(
cacheNames.map( cacheName => {
/* Deleting all the caches except the ones that are in cacheWhitelist array */
if (cacheWhitelist.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