-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
34 lines (32 loc) · 957 Bytes
/
Copy pathsw.js
File metadata and controls
34 lines (32 loc) · 957 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
28
29
30
31
32
33
34
// https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Offline_Service_workers
const cacheName = 'lolidk';
const appShellFiles = [
'./',
'js/utils.js',
'js/idb-keyval.js',
'style.css',
'manifest.json',
'fonts/roboto.css',
'fonts/Roboto-Regular.ttf',
'fonts/Roboto-Medium.ttf',
'icons/logo.svg',
'icons/logo192.png',
'icons/logo512.png',
];
self.addEventListener('install', (e) => {
console.log('[Service Worker] Install');
e.waitUntil((async () => {
const cache = await caches.open(cacheName);
console.log('[Service Worker] Caching all: app shell and content');
await cache.addAll(appShellFiles);
})());
});
self.addEventListener('fetch', (e) => {
e.respondWith((async () => {
const r = await caches.match(e.request);
if (r) { return r; }
console.log(`[Service Worker] Fetching resource: ${e.request.url}`);
const response = await fetch(e.request);
return response;
})());
});