-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserviceWorker.js
50 lines (48 loc) · 1.34 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
const resoursesToCache = [
// HTML
'/index.html',
'/feedback.html',
// CSS
'/assets/css/style.css',
// JS
'/assets/js/formReset.js',
'/assets/js/index.js',
'/assets/js/Metronome.js',
'/assets/js/Move.js',
'/assets/js/Turn.js',
'/assets/js/unmute.js',
// images
'/assets/images/marching-shoe.svg',
'/assets/images/metronome.svg',
// fonts
'/assets/fonts/montserrat-v15-latin-700.eot',
'/assets/fonts/montserrat-v15-latin-700.svg',
'/assets/fonts/montserrat-v15-latin-700.ttf',
'/assets/fonts/montserrat-v15-latin-700.woff',
'/assets/fonts/montserrat-v15-latin-700.woff2',
'/assets/fonts/montserrat-v15-latin-regular.eot',
'/assets/fonts/montserrat-v15-latin-regular.svg',
'/assets/fonts/montserrat-v15-latin-regular.ttf',
'/assets/fonts/montserrat-v15-latin-regular.woff',
'/assets/fonts/montserrat-v15-latin-regular.woff2',
// external resources
'https://use.fontawesome.com/releases/v5.15.3/css/all.css',
]
// On install - cache resources
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open('sw-cache').then((cache) => {
cache.addAll(resoursesToCache)
})
)
})
// with requeset network
self.addEventListener('fetch', (e) => {
e.respondWith(
// try the cache
caches.match(e.request).then((response) => {
// return it if there is a response, or else fetch again
return response || fetch(e.request)
})
)
})