static/service-worker: Update cache buster from MDN docs

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
Harsh Shandilya 2019-10-26 20:37:23 +05:30
parent 819cd2ebfc
commit bf55d0857f
1 changed files with 15 additions and 4 deletions

View File

@ -1,4 +1,3 @@
const oldCaches = ['cache-v1', 'cache-v2', 'cache-v3']
const cacheName = 'cache-v4'
const precacheResources = [
'/',
@ -40,9 +39,21 @@ self.addEventListener('install', event => {
})
self.addEventListener('activate', event => {
for (id in oldCaches) {
self.caches.delete(id)
}
var cacheKeeplist = [cacheName]
event.waitUntil(
caches
.keys()
.then(keyList => {
return Promise.all(
keyList.map(key => {
if (cacheKeeplist.indexOf(key) === -1) {
return caches.delete(key)
}
})
)
})
.then(self.clients.claim())
)
})
self.addEventListener('fetch', event => {