2023-03-07 03:54:26 +00:00
|
|
|
// This is the "Offline page" service worker
|
|
|
|
|
2023-07-05 15:41:17 -05:00
|
|
|
importScripts(
|
|
|
|
"https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js"
|
|
|
|
);
|
2023-03-07 03:54:26 +00:00
|
|
|
|
2023-03-09 01:50:32 +00:00
|
|
|
const CACHE = "crafty-controller";
|
2023-03-07 03:54:26 +00:00
|
|
|
|
|
|
|
// TODO: replace the following with the correct offline fallback page i.e.: const offlineFallbackPage = "offline.html";
|
|
|
|
const offlineFallbackPage = "/offline";
|
|
|
|
|
|
|
|
self.addEventListener("message", (event) => {
|
2023-07-05 15:41:17 -05:00
|
|
|
if (event.data && event.data.type === "SKIP_WAITING") {
|
|
|
|
self.skipWaiting();
|
|
|
|
}
|
2023-03-07 03:54:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (workbox.navigationPreload.isSupported()) {
|
2023-07-05 15:41:17 -05:00
|
|
|
workbox.navigationPreload.enable();
|
2023-03-07 03:54:26 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 15:41:17 -05:00
|
|
|
// 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;
|
|
|
|
// }
|
|
|
|
// })());
|
|
|
|
// }
|
|
|
|
// });
|