FIX: js/pwabuilder-sw.js
This commit is contained in:
@@ -1,39 +1,18 @@
|
|||||||
// This is the "Offline page" service worker
|
// This is the "Offline copy of pages" service worker
|
||||||
|
|
||||||
|
const CACHE = "darkshy-offline";
|
||||||
|
|
||||||
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
|
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
|
||||||
|
|
||||||
const CACHE = "darkshy-page";
|
|
||||||
|
|
||||||
// TODO: replace the following with the correct offline fallback page i.e.: const offlineFallbackPage = "offline.html";
|
|
||||||
const offlineFallbackPage = "offline.html";
|
|
||||||
|
|
||||||
self.addEventListener("message", (event) => {
|
self.addEventListener("message", (event) => {
|
||||||
if (event.data && event.data.type === "SKIP_WAITING") {
|
if (event.data && event.data.type === "SKIP_WAITING") {
|
||||||
self.skipWaiting();
|
self.skipWaiting();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('install', async (event) => {
|
workbox.routing.registerRoute(
|
||||||
event.waitUntil(
|
new RegExp('/*'),
|
||||||
caches.open(CACHE)
|
new workbox.strategies.StaleWhileRevalidate({
|
||||||
.then((cache) => cache.add(offlineFallbackPage))
|
cacheName: CACHE
|
||||||
);
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user