Correct SW Bug when reload
This commit is contained in:
parent
3a7197207f
commit
2f73234764
@ -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) {
|
||||||
@ -60,7 +66,7 @@ self.addEventListener('fetch', function (event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refresh(response) {
|
function refresh(response) {
|
||||||
if(response){
|
if (response) {
|
||||||
return self.clients.matchAll().then(function (clients) {
|
return self.clients.matchAll().then(function (clients) {
|
||||||
clients.forEach(function (client) {
|
clients.forEach(function (client) {
|
||||||
var message = {
|
var message = {
|
||||||
|
Loading…
Reference in New Issue
Block a user