-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceWorker.js
74 lines (65 loc) · 1.79 KB
/
serviceWorker.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
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const cacheName = 'kanban'
const buildCache = async () => {
const files = [
'/',
'/index.html',
'/manifest.webmanifest',
'/css/base.css',
'/css/components/app.css',
'/css/components/board.css',
'/css/components/column.css',
'/css/components/dialog.css',
'/css/components/subtask.css',
'/css/components/task.css',
'/css/fonts.css',
'/css/main.css',
'/css/reset.css',
'/favicon/apple-touch-icon.png',
'/favicon/icon-192.png',
'/favicon/icon-512.png',
'/favicon/icon-maskable-192.png',
'/favicon/icon-maskable-512.png',
'/favicon/icon.ico',
'/favicon/icon.svg',
'/favicon/mask-icon.svg',
'/fonts/PlusJakartaSans-Bold.woff2',
'/fonts/PlusJakartaSans-ExtraBold.woff2',
'/fonts/PlusJakartaSans-Medium.woff2',
'/js/arrow.js',
'/js/components/App.js',
'/js/components/Board.js',
'/js/components/Column.js',
'/js/components/Dropdown.js',
'/js/components/Subtask.js',
'/js/components/Task.js',
'/js/components/dialogs/BoardFormDialog.js',
'/js/components/dialogs/ColumnFormDialog.js',
'/js/components/dialogs/ConfirmDialog.js',
'/js/components/dialogs/Dialog.js',
'/js/components/dialogs/TaskDialog.js',
'/js/components/dialogs/TaskFormDialog.js',
'/js/generateId.js',
'/js/loadDataSample.js'
]
const root = '/Task-Management-Web-App'
const filesToCache = files.map(url => root + url)
const cache = await caches.open(cacheName)
await cache.addAll(filesToCache)
}
self.addEventListener('install', e => {
e.waitUntil(buildCache())
})
const getResp = async (request) => {
const cache = await caches.open(cacheName)
try {
const resp = await fetch(request)
if (resp.ok) cache.put(request, resp.clone())
return resp
}
catch {
return await cache.match(request)
}
}
self.addEventListener('fetch', e => {
e.respondWith(getResp(e.request))
})