v1.5.1 - Fixed caching

This commit is contained in:
Frederik Milling Pytlick 2020-11-30 21:13:20 +01:00 committed by GitHub
parent 4db9d2836b
commit adfedee25f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 8 deletions

View File

@ -58,18 +58,22 @@ self.addEventListener('activate', evt => {
self.addEventListener('fetch', evt => {
console.log('fetch event');
evt.respondWith(
caches.match(evt.request).then(cacheRes => {
return cacheRes || fetch(evt.request).then(fetchRes => {
if(!navigator.onLine)
evt.respondWith(
caches.match(evt.request).then(cacheRes => {
return cacheRes || caches.match('/offline.html');
})
);
else
evt.respondWith(
fetch(evt.request).then(fetchRes => {
return caches.open(dynamicCacheName).then(cache => {
cache.put(evt.request.url, fetchRes.clone());
return fetchRes;
})
});
}).catch(function () {
return caches.match('/offline.html');
})
);
})
);
});
self.addEventListener('push', function(event) {