-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCB-worker.js
More file actions
27 lines (25 loc) · 771 Bytes
/
CB-worker.js
File metadata and controls
27 lines (25 loc) · 771 Bytes
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
// (A) CREATE/INSTALL CACHE
self.addEventListener("install", evt => {
self.skipWaiting();
evt.waitUntil(
caches.open("NotesPWA")
.then(cache => cache.addAll([
"assets/favicon.png",
"assets/head-notes-pwa.webp",
"assets/icon-512.png",
"assets/js-notes-db.js",
"assets/js-notes.js",
"assets/js-notes.css",
"assets/maticon.woff2",
"CB-manifest.json",
"js-notes.html"
]))
.catch(err => console.error(err))
);
});
// (B) CLAIM CONTROL INSTANTLY
self.addEventListener("activate", evt => self.clients.claim());
// (C) LOAD FROM CACHE FIRST, FALLBACK TO NETWORK IF NOT FOUND
self.addEventListener("fetch", evt => evt.respondWith(
caches.match(evt.request).then(res => res || fetch(evt.request))
));