Skip to content

Instantly share code, notes, and snippets.

@osvaldasvalutis
Created October 2, 2017 07:34
Show Gist options
  • Save osvaldasvalutis/69ddf0f883b3fb8724f2fdb777690c2f to your computer and use it in GitHub Desktop.
Save osvaldasvalutis/69ddf0f883b3fb8724f2fdb777690c2f to your computer and use it in GitHub Desktop.
const clearOldCaches = () => {
return caches.keys().then(keys => {
return Promise.all(keys.filter(key => !key.startsWith(version)).map(key => caches.delete(key)));
});
};
self.addEventListener('activate', event => {
event.waitUntil(clearOldCaches().then(() => self.clients.claim()));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment