Purge old caches during service worker init

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
Harsh Shandilya 2019-09-24 00:25:57 +05:30
parent f333b9af35
commit e14de726e9
1 changed files with 11 additions and 0 deletions

View File

@ -1,3 +1,4 @@
const oldCaches = ['cache-v1', 'cache-v2']
const cacheName = 'cache-v3';
const precacheResources = [
'/',
@ -30,6 +31,16 @@ const precacheResources = [
'/posts/teaching-kotlin-classes-and-objects/index.html',
];
for (id in oldCaches) {
caches.open(id).then(cache =>
cache.keys().then(keys => {
for (let key of keys) {
cache.delete(key)
}
})
)
}
self.addEventListener('install', event => {
console.log('Service worker install event!');
event.waitUntil(