Skip to content

Instantly share code, notes, and snippets.

@ritikrishu
Created March 11, 2018 21:41
Show Gist options
  • Save ritikrishu/d4990dade15966894c744158dcf415c7 to your computer and use it in GitHub Desktop.
Save ritikrishu/d4990dade15966894c744158dcf415c7 to your computer and use it in GitHub Desktop.
delete previous version static caches from CacheStorage
/**
suppose, static caches are categorized as static-imgs-v1, static-js-v1...
*/
const version = 'v2';
const staticPrefix = 'static-'
caches.keys().then(function (cacheNames) {
return Promise.all(
cacheNames.filter(function (cacheName) {
return cacheName.startsWith(staticPrefix) &&
!cacheName.endsWith(version);
}).map(function (cacheName) {
return caches.delete(cacheName);
})
);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment