Change SW cache technique
This commit is contained in:
parent
09e95c1b65
commit
d2213990e1
@ -6,13 +6,13 @@ self.addEventListener('fetch', function(event) {
|
|||||||
|
|
||||||
function fetchAndCache(event) {
|
function fetchAndCache(event) {
|
||||||
return caches.open(CACHE).then(function (cache) {
|
return caches.open(CACHE).then(function (cache) {
|
||||||
return fetch(event.request)
|
return cache.match(event.request).then(response => {
|
||||||
.then(function(response) {
|
var fetchResponse = fetch(event.request)
|
||||||
cache.put(event.request, response.clone());
|
.then(function(networkResponse) {
|
||||||
return response;
|
cache.put(event.request, networkResponse.clone());
|
||||||
})
|
return networkResponse;
|
||||||
.catch(function() {
|
});
|
||||||
return cache.match(event.request);
|
return response || fetchResponse;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user