Answer the question
In order to leave comments, you need to log in
How to update the cache?
var version='5.3.7.1';
self.addEventListener('install',function(ev){
ev.waitUntil(caches.open(version).then(function(cache){
if(location.protocol=='http:'||location.protocol=='https:'){
return fetch('/resource.json').then(function(res){
return res.json();
}).then(function(files){
return cache.addAll(files);
});
}
}));
self.skipWaiting();
});
self.addEventListener('activate',function(ev){
ev.waitUntil(caches.keys().then(function(keyList){
return Promise.all(keyList.map(function(key){
if(version!=key){
return caches.delete(key);
}
}));
}));
});
self.addEventListener('fetch',function(ev){
ev.respondWith(caches.match(ev.request).then(function(res){
return res||fetch(ev.request).then(function(res){
var resToCache=res.clone();
caches.open(version).then(function(cache){
if(ev.request.method!='POST'){
cache.put(ev.request,resToCache);
}
});
return res;
}).catch(function(){
return caches.match('/offline.html');
});
}));
});
Answer the question
In order to leave comments, you need to log in
Is there a assembler? In any, you can configure so that a hash is added to the file name.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question