I have fixed it
Line // If any fetch fails, it will show the offline page.
Replly
// If any fetch fails, it will show the offline page.
self.addEventListener("fetch", function (event) {
// Return if the current request url is in the never cache list
if ( ! neverCacheUrls.every(checkNeverCacheList, event.request.url) ) {
console.log( '[PWA] Current request is excluded from cache.' );
return;
}
// Return if request url protocal isn't http or https
if ( ! event.request.url.match(/^(http|https):\/\//i) )
return;
// Return if request url is from an external domain.
if ( new URL(event.request.url).origin !== location.origin )
return;
// For POST requests, do not use the cache. Serve offline page if offline.
if ( event.request.method !== 'GET' ) {
event.respondWith(
fetch(event.request).catch( function() {
return caches.match(offlineFallbackPage);
})
);
return;
}
// For Range Headers
if (event.request.headers.has('range')) {
return;
}
// Revving strategy
if ( (event.request.mode === 'navigate' || event.request.mode === 'cors') && navigator.onLine ) {
event.respondWith(
fetch(event.request).then(function(response) {
return caches.open(CACHE).then(function(cache) {
cache.put(event.request, response.clone());
return response;
});
}).catch(function(){
// If the network is unavailable, get
return cache.match(event.request.url);
})
);
return;
}
//strategy_replace_start
event.respondWith(
caches.match(event.request).then(res => {
if (
event.request.method !== 'GET' ||
forumPayload.debug && forumPayload.clockworkEnabled ||
!res
) {
return fetch(event.request);
}
return res;
}).catch(error => {
// The following validates that the request was for a navigation to a new document
if (
event.request.destination !== "document" ||
event.request.mode !== "navigate"
) {
throw error;
}
return caches.open(CACHE).then(function (cache) {
return cache.match(offlineFallbackPage);
});
})
);
//strategy_replace_end
});
// Check if current url is in the neverCacheUrls list
function checkNeverCacheList(url) {
if ( this.match(url) ) {
return false;
}
return true;
}