mirror of
https://github.com/Brandon-Rozek/website-theme.git
synced 2024-12-22 17:12:27 +00:00
Offline page URL fix
This commit is contained in:
parent
5ae3c63834
commit
31dfeaaa0b
1 changed files with 14 additions and 10 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue