-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f8940d
commit 53160ad
Showing
1 changed file
with
43 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
// }) | ||
// ); |