Offline page URL fix

This commit is contained in:
Brandon Rozek 2024-10-20 12:36:35 -04:00
parent 5ae3c63834
commit 31dfeaaa0b
No known key found for this signature in database
GPG key ID: 26E457DA82C9F480

View file

@ -1,6 +1,6 @@
let version = 'v1::';
let cacheName = 'website';
let offlinePage = '/offline';
let offlinePage = '/offline/';
let offlineFundamentals = [offlinePage, '/'];
let maxItems = 100;
@ -89,21 +89,25 @@ if (registration.navigationPreload) {
self.addEventListener('fetch', function (event) {
const request = event.request;
// Always fetch non-GET requests from the network
if (request.method !== 'GET') {
event.respondWith(
fetch(request)
.catch(() => caches.match(offlinePage))
);
return;
}
let isRequestType = function(name) {
return request.headers
.get('Accept')
.includes(name);
}
// Always fetch non-GET requests from the network
if (request.method !== 'GET') {
// Present offline page when failed to
// fetch a HTML page
if (isRequestType('text/html')) {
event.respondWith(
fetch(request)
.catch(() => caches.match(offlinePage))
);
}
return;
}
// Network-first Approach
event.respondWith(
// Attepmt to grab the latest copy from the network