From a690f561a36a93cf1bb8c16198bc4a4b5515c6a1 Mon Sep 17 00:00:00 2001 From: DarkShy Date: Sat, 14 Jan 2023 02:16:58 +0300 Subject: [PATCH] modified: index.html --- index.html | 12 +++++++--- js/pwabuilder-sw.js | 55 +++++++++------------------------------------ 2 files changed, 19 insertions(+), 48 deletions(-) diff --git a/index.html b/index.html index 9f0d4de..d664576 100644 --- a/index.html +++ b/index.html @@ -28,8 +28,14 @@ \ No newline at end of file diff --git a/js/pwabuilder-sw.js b/js/pwabuilder-sw.js index 80630ff..f17a005 100644 --- a/js/pwabuilder-sw.js +++ b/js/pwabuilder-sw.js @@ -1,47 +1,12 @@ -// This is the "Offline page" service worker +var cacheName = 'darkshy-cache-v1'; +var assetsToCache = ['css/style.css']; -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) => { - 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; - } - - const networkResp = await fetch(event.request); - return networkResp; - } catch (error) { - - const cache = await caches.open(CACHE); - const cachedResp = await cache.match(offlineFallbackPage); - return cachedResp; - } - })()); - } +self.addEventListener('install', function(event) { + event.waitUntil( + caches.open(cacheName) + .then(function(cache) { + console.log('Opened cache'); + return cache.addAll(assetsToCache); + }) + ); }); \ No newline at end of file