-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsw.js
executable file
·59 lines (54 loc) · 1.17 KB
/
sw.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
const assets = [
'./manifest.json',
'./ico.png',
'./icon.png',
'./index.html',
'./main.css',
'./dist/wavesurfer.js',
'./dist/plugin/wavesurfer.regions.js',
'./oneup.js',
'./app.js',
'./keys.js',
'./contextmenu.js',
'./ui-fx.js',
'./ui.js',
'./modal.js',
'./state.js',
'./engine.js',
'./actions.js',
'./drag.js',
'./recorder.js',
'./welcome.js',
'./fx-pg-eq.js',
'./fx-auto.js',
'./local.js',
'./id3.js',
'./lzma.js',
'./lame.js',
'./fonts/icomoon.ttf',
'./fonts/icomoon.woff',
'./favicon.ico',
'./eq.html',
'./sp.html',
'./test.mp3'
];
self.addEventListener( 'install', async function () {
const cache = await caches.open( 'audiomass' );
assets.forEach( function ( asset ) {
cache.add( asset ).catch( function () {
console.error( '[SW] Cound\'t cache:', asset );
});
});
});
self.addEventListener( 'fetch', async function ( event ) {
const request = event.request;
event.respondWith( cacheFirst( request ) );
});
async function cacheFirst( request ) {
const cachedResponse = await caches.match( request );
if ( cachedResponse === undefined ) {
console.error( '[SW] Not cached:', request.url );
return fetch( request );
}
return cachedResponse;
}