mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 22:55:35 +00:00
maybe an actually good service worker for once
This commit is contained in:
28
src/sw.js
28
src/sw.js
@@ -3,6 +3,14 @@ console.log('Hello from sw.js');
|
|||||||
if (workbox) {
|
if (workbox) {
|
||||||
console.log('Yay! Workbox is loaded 🎉');
|
console.log('Yay! Workbox is loaded 🎉');
|
||||||
workbox.precaching.precacheAndRoute(self.__precacheManifest);
|
workbox.precaching.precacheAndRoute(self.__precacheManifest);
|
||||||
|
|
||||||
|
workbox.routing.registerNavigationRoute('/index.html');
|
||||||
|
|
||||||
|
workbox.routing.registerRoute(
|
||||||
|
new RegExp('/(.*?)'),
|
||||||
|
workbox.strategies.staleWhileRevalidate()
|
||||||
|
);
|
||||||
|
|
||||||
workbox.routing.registerRoute(
|
workbox.routing.registerRoute(
|
||||||
new RegExp('https://fonts.(?:googleapis|gstatic).com/(.*)'),
|
new RegExp('https://fonts.(?:googleapis|gstatic).com/(.*)'),
|
||||||
workbox.strategies.cacheFirst({
|
workbox.strategies.cacheFirst({
|
||||||
@@ -41,23 +49,3 @@ self.addEventListener('message', event => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const OFFLINE_URL = '/';
|
|
||||||
self.addEventListener('fetch', function(event) {
|
|
||||||
console.log('Handling fetch event for', event.request.url);
|
|
||||||
|
|
||||||
event.respondWith(
|
|
||||||
caches.match(event.request).then(function(response) {
|
|
||||||
if (response) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fetch(event.request)
|
|
||||||
.then(function(response) {
|
|
||||||
return response;
|
|
||||||
})
|
|
||||||
.catch(function(error) {
|
|
||||||
return caches.match(OFFLINE_URL);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user