-
Notifications
You must be signed in to change notification settings - Fork 1
/
service-worker.js
60 lines (55 loc) · 1.13 KB
/
service-worker.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
const FILES_TO_CACHE = [
'css/style.css',
'index.html',
'app/app.js',
// Images
'images/0.png',
'images/1.png',
'images/2.png',
'images/3.png',
'images/4.png',
'images/5.png',
'images/6.png',
'images/7.png',
'images/8.png',
'images/9.png',
'images/10.png',
'images/11.png',
'images/12.png',
'images/13.png',
'images/14.png',
'images/dj_alt.jpg',
'images/dj.jpg',
'images/scrobbling.gif',
'images/4chon.ico'
]
const CACHE_NAME = 'shinobu-cache-v6'
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
return cache.addAll(FILES_TO_CACHE)
})
)
})
// Remove cache entries that aren't expected
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(keys =>
Promise.all(
keys.map(key => {
if (key !== CACHE_NAME) return caches.delete(key)
})
)
)
)
})
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(response => {
if (response) {
return response
}
return fetch(event.request)
})
)
})