-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
34 lines (31 loc) · 898 Bytes
/
service-worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Name of the Cache.
const CACHE = "cacheV1";
// Select files for caching.
let urlsToCache = [
"/",
"/index.html",
"/components",
"/components/images/felix.png",
"/components/scripts",
"/components/scripts/pwa-handler.js",
];
// Cache all the selected items once application is installed.
self.addEventListener("install", (event) => {
event.waitUntil(
caches.open(CACHE).then((cache) => {
console.log("Caching started.");
return cache.addAll(urlsToCache);
})
);
});
// Whenever a resource is requested, return if its cached else fetch the resourcefrom server.
self.addEventListener("fetch", (event) => {
event.respondWith(
caches.match(event.request).then((response) => {
if (response) {
return response;
}
return fetch(event.request);
})
);
});