Correct SW Bug when reload

This commit is contained in:
Sebastien 2018-09-25 15:11:12 +03:00
parent 3a7197207f
commit 2f73234764

View File

@ -26,26 +26,32 @@ self.addEventListener('install', function (event) {
}); });
self.addEventListener('fetch', function (event) { self.addEventListener('fetch', function (event) {
event.respondWith(
caches.match(event.request)
.then(function (response) { var request = event.request;
// Cache hit - return response
if (response) { event.respondWith(fetch(request).catch( function (reason) {
return response; console.error(
} '[onfetch] Failed. Serving cached offline fallback ' +
return fetch(event.request); reason
}
)
); );
return caches.open(CACHE_NAME).then(function(cache){
return cache.match(request);
})
}));
event.waitUntil( event.waitUntil(
update(event.request) update(event.request)
.then(refresh) .then(refresh, function (reason) {
console.log("Update fail");
console.log(event.request)
})
); );
function update(request) { function update(request) {
return caches.match(request).then( return caches.match(request).then(function (response) {
function (response) {
if (response) { if (response) {
return caches.open(CACHE_NAME).then(function (cache) { return caches.open(CACHE_NAME).then(function (cache) {
return fetch(request).then(function (response) { return fetch(request).then(function (response) {