-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
59 lines (59 loc) · 1.89 KB
/
sw.js
File metadata and controls
59 lines (59 loc) · 1.89 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const CACHE_NAME = 'homeorganizer-v10';
const PRECACHE = [
'./',
'./index.html',
'./manifest.json',
'./assets/icons/pwa/icon-32.png',
'./assets/icons/pwa/icon-64.png',
'./assets/icons/pwa/apple-touch-icon.png',
'./assets/icons/pwa/icon-192.png',
'./assets/icons/pwa/icon-512.png',
'./assets/icons/pwa/icon-1024.png',
'./styles/design-system.css',
'./js/db/idb.js',
'./js/logic/recurrence.js',
'./js/logic/plannerCore.js',
'./js/logic/scheduler.js',
'./js/ui/cardStack.js',
'./js/ui/listSwipe.js',
'./js/ui/app.js',
'./assets/icons/material/calendar_today.svg',
'./assets/icons/material/checklist.svg',
'./assets/icons/material/bar_chart.svg',
'./assets/icons/material/settings.svg',
'./assets/icons/material/refresh.svg',
'./assets/icons/material/check_circle.svg',
'./assets/icons/material/add.svg',
'./assets/icons/material/delete.svg',
'./assets/icons/material/dark_mode.svg',
'./assets/icons/material/light_mode.svg'
];
self.addEventListener('message', e => {
if (e.data && e.data.type === 'SKIP_WAITING') self.skipWaiting();
});
self.addEventListener('install', e => {
e.waitUntil(
caches.open(CACHE_NAME)
.then(c => c.addAll(PRECACHE.map(u => new URL(u, self.registration.scope).toString())))
.then(() => self.skipWaiting())
);
});
self.addEventListener('activate', e => {
e.waitUntil(
caches.keys().then(keys => Promise.all(keys.filter(k => k !== CACHE_NAME).map(k => caches.delete(k)))).then(() => self.clients.claim())
);
});
self.addEventListener('fetch', e => {
const req = e.request;
if (req.method !== 'GET') return;
e.respondWith(
caches.match(req).then(cached => {
const fetchPromise = fetch(req).then(res => {
const resClone = res.clone();
caches.open(CACHE_NAME).then(c => c.put(req, resClone));
return res;
}).catch(() => cached);
return cached || fetchPromise;
})
);
});