crafty-4/app/frontend/static/assets/js/shared/service-worker.js
2023-07-29 16:05:27 -05:00

42 lines
1.1 KiB
JavaScript

// This is the "Offline page" service worker
importScripts(
"https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js"
);
const CACHE = "crafty-controller";
// TODO: replace the following with the correct offline fallback page i.e.: const offlineFallbackPage = "offline.html";
const offlineFallbackPage = "/offline";
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
if (workbox.navigationPreload.isSupported()) {
workbox.navigationPreload.enable();
}
// self.addEventListener('fetch', (event) => {
// if (event.request.mode === 'navigate') {
// event.respondWith((async () => {
// try {
// const preloadResp = await event.preloadResponse;
// if (preloadResp) {
// return preloadResp;
// }
// const networkResp = await fetch(event.request);
// return networkResp;
// } catch (error) {
// const cache = await caches.open(CACHE);
// const cachedResp = await cache.match(offlineFallbackPage);
// return cachedResp;
// }
// })());
// }
// });