modified: js/pwabuilder-sw.js
This commit is contained in:
@@ -1,12 +1,35 @@
|
|||||||
var cacheName = 'darkshy-cache-v1';
|
// This is the "Offline page" service worker
|
||||||
var assetsToCache = ['css/style.css'];
|
|
||||||
|
|
||||||
self.addEventListener('install', function(event) {
|
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
|
||||||
event.waitUntil(
|
|
||||||
caches.open(cacheName)
|
const CACHE = "darkshy-page";
|
||||||
.then(function(cache) {
|
|
||||||
console.log('Opened cache');
|
// TODO: replace the following with the correct offline fallback page i.e.: const offlineFallbackPage = "offline.html";
|
||||||
return cache.addAll(assetsToCache);
|
const offlineFallbackPage = "offline.html";
|
||||||
})
|
|
||||||
);
|
self.addEventListener("message", (event) => {
|
||||||
|
if (event.data && event.data.type === "SKIP_WAITING") {
|
||||||
|
self.skipWaiting();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.addEventListener('install', async (event) => {
|
||||||
|
event.waitUntil(
|
||||||
|
caches.open(CACHE)
|
||||||
|
.then((cache) => cache.add(offlineFallbackPage))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
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