Changed to network-first caching
This commit is contained in:
parent
4fb38ae95a
commit
cca58fa179
@ -1,4 +1,8 @@
|
|||||||
var CACHE = 'v2';
|
var CACHE = 'v3';
|
||||||
|
|
||||||
|
self.addEventListener('install', function() {
|
||||||
|
return self.skipWaiting();
|
||||||
|
})
|
||||||
|
|
||||||
self.addEventListener('fetch', function(event) {
|
self.addEventListener('fetch', function(event) {
|
||||||
event.respondWith(fetchAndCache(event));
|
event.respondWith(fetchAndCache(event));
|
||||||
@ -18,13 +22,14 @@ function cacheBust(request) {
|
|||||||
|
|
||||||
function fetchAndCache(event) {
|
function fetchAndCache(event) {
|
||||||
return caches.open(CACHE).then(function (cache) {
|
return caches.open(CACHE).then(function (cache) {
|
||||||
return cache.match(event.request).then(response => {
|
return fetch(event.request)
|
||||||
var fetchResponse = fetch(cacheBust(event.request))
|
|
||||||
.then(function(networkResponse) {
|
.then(function(networkResponse) {
|
||||||
cache.put(event.request, networkResponse.clone());
|
cache.put(event.request, networkResponse.clone());
|
||||||
return networkResponse;
|
return networkResponse;
|
||||||
});
|
})
|
||||||
return response || fetchResponse;
|
.catch(function(err) {
|
||||||
|
console.log(err)
|
||||||
|
return caches.match(event.request);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user