-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
37 lines (31 loc) · 928 Bytes
/
Copy pathsw.js
File metadata and controls
37 lines (31 loc) · 928 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
35
36
37
const APP_NAME = 'ppluss-yearprogress'
const APP_VERSION = '0.0.3'
const APP_ROOT = '/'
const CACHE_NAME = APP_NAME + '-v' + APP_VERSION
const appFiles = [
'',
'style.css',
'main.js',
'moment.js',
'manifest.json',
'icon.png',
].map(file => APP_ROOT + file)
self.addEventListener('install', event => {
event.waitUntil((async () => {
// clear all caches on reinstall
const oldCaches = await caches.keys()
for(const cacheName of oldCaches) {
await caches.delete(cacheName)
}
const cache = await caches.open(CACHE_NAME)
await cache.addAll(appFiles)
})())
})
self.addEventListener('fetch', event => {
event.respondWith((async () => {
const cache = await caches.open(CACHE_NAME)
const match = await cache.match(event.request)
if(match) return match
return await fetch(event.request)
})())
})