-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
50 lines (47 loc) · 1.45 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
const cacheName = 'listenup-v1';
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(cacheName).then((cache) => {
return cache.addAll([
'./',
'./index.html',
'./main.css',
'./app.js',
'icons/icon-96x96.png',
'icons/icon-128x128.png',
'icons/icon-152x152.png',
'icons/icon-192x192.png',
'icons/icon-512x512.png',
'music/bach-cello-suite-1-prelude.mp3',
// 'music/debussy-clair-de-lune.mp3',
// 'music/beethoven-piano-sonata-14-moonlight.mp3',
// 'music/beethoven-symphony-9-choral-excerpt.mp3.',
// 'music/chopin-nocturne-2-e-flat-major.mp3',
// 'music/debussy-prelude-to-the-afternoon-of-a-faun.mp3',
// 'music/la-traviata-brindisi-verdi.mp3',
// 'music/mozart-overture-to-the-marriage-of-figaro-k.mp3',
// 'music/mozart-string-quartet-21-prussian.mp3'
]);
})
);
});
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(existingCacheNames => {
return Promise.all(
existingCacheNames.map(existingCacheName => {
if (existingCacheName !== cacheName) {
return caches.delete(existingCacheName);
}
})
);
})
);
});
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((response) => {
return response || fetch(event.request);
})
);
});