Skip to content

Instantly share code, notes, and snippets.

@mp5maker
Created December 5, 2020 04:40
Show Gist options
  • Save mp5maker/d7fc63864a9aa71bf287077669868ebc to your computer and use it in GitHub Desktop.
Save mp5maker/d7fc63864a9aa71bf287077669868ebc to your computer and use it in GitHub Desktop.
Activate Event
self.addEventListener('activate', (event) => {
console.log("SW Activate Event: Is in the process")
// Google Chrome browseer -> console -> application -> cache -> cache storage
const onSuccessCachesKeys = (cacheNames) => {
// List of cachenames generated by STATIC_CACHE_VERSION
console.log(cacheNames)
// Loop through all the keys stored in cache storage
return Promise.all(
cacheNames.map((cache) => {
if (cache !== STATIC_CACHE_VERSION) {
console.log(`SW Activate Event: Remove the cache: ${cache}`);
return caches.delete(cache)
}
})
)
}
event.waitUntil(caches.keys().then(onSuccessCachesKeys))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment