Почему загрузка ресурсов через sw занимает время?
var version='v1';
self.addEventListener('install',function(event){
event.waitUntil(caches.open(version).then(function(cache){
if(location.protocol=='http:'||location.protocol=='https:'){
return fetch('./resource.json').then(function(response){
return response.json();
}).then(function(files){
return cache.addAll(files);
});
}
}));
});
self.addEventListener('activate',function(event){
event.waitUntil(caches.keys().then(function(keyList){
return Promise.all(keyList.map(function(key){
if(version!=key)
return caches.delete(key);
}));
}));
});
self.addEventListener('fetch',function(event){
event.respondWith(caches.match(event.request).then(function(response){
if(response)
return response;
return fetch(event.request).then(function(response){
if(!response||response.status!==200||response.type!=='basic')
return response;
var responseToCache=response.clone();
caches.open(version).then(function(cache){
if(event.request.url.split('://')[0]!='chrome-extension'){
if(event.request.method!='POST')
cache.put(event.request,responseToCache);
}
});
return response;
}).catch(function(){
return caches.match('/offline.html');
});
}));
});