Skip to content

Commit

Permalink
Update service-worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mhadi-1382 committed Jan 28, 2024
1 parent 2f8940d commit 53160ad
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions service-worker.js
Original file line number Diff line number Diff line change
@@ -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
})
);
// workbox.routing.registerRoute(
// new RegExp('/*'),
// new workbox.strategies.StaleWhileRevalidate({
// cacheName: CACHE
// })
// );

0 comments on commit 53160ad

Please sign in to comment.