From 53160ad5dea8f706cce9df6e304b8e75eabd821c Mon Sep 17 00:00:00 2001 From: Mahdi <82710784+Mhadi-1382@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:33:36 +0330 Subject: [PATCH] Update service-worker.js --- service-worker.js | 56 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/service-worker.js b/service-worker.js index 3f11d26..2523f63 100644 --- a/service-worker.js +++ b/service-worker.js @@ -1,18 +1,48 @@ +var cacheName = 'itst-pwa'; +var filesToCache = [ + '/', + '/index.html', + '/css/style.css', + '/js/app.js' +]; + +/* Start the service worker and cache all of the app's content */ +self.addEventListener('install', function(e) { + e.waitUntil( + caches.open(cacheName).then(function(cache) { + return cache.addAll(filesToCache); + }) + ); + self.skipWaiting(); +}); + +/* Serve cached content when offline */ +self.addEventListener('fetch', function(e) { + e.respondWith( + caches.match(e.request).then(function(response) { + return response || fetch(e.request); + }) + ); +}); + + + + // This is the "Offline copy of assets" service worker -const CACHE = "pwabuilder-offline"; +// const CACHE = "pwabuilder-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'); -self.addEventListener("message", (event) => { - if (event.data && event.data.type === "SKIP_WAITING") { - self.skipWaiting(); - } -}); +// self.addEventListener("message", (event) => { +// if (event.data && event.data.type === "SKIP_WAITING") { +// self.skipWaiting(); +// } +// }); -workbox.routing.registerRoute( - new RegExp('/*'), - new workbox.strategies.StaleWhileRevalidate({ - cacheName: CACHE - }) -); \ No newline at end of file +// workbox.routing.registerRoute( +// new RegExp('/*'), +// new workbox.strategies.StaleWhileRevalidate({ +// cacheName: CACHE +// }) +// );