-
-
Notifications
You must be signed in to change notification settings - Fork 175
/
sw.js
111 lines (77 loc) · 2.31 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const cacheName = 'framejs-editor';
const assets = [
'./',
'./manifest.json',
'./files/icon.png',
'./css/main.css',
'./css/dark.css',
'./files/fullscreen.svg',
'./files/next.svg',
'./files/pause.svg',
'./files/play.svg',
'./files/prev.svg',
'./js/libs/codemirror/codemirror.css',
'./js/libs/codemirror/codemirror.js',
'./js/libs/codemirror/addon/dialog/dialog.css',
'./js/libs/codemirror/addon/dialog/dialog.js',
'./js/libs/codemirror/addon/scroll/annotatescrollbar.js',
'./js/libs/codemirror/addon/scroll/scrollpastend.js',
'./js/libs/codemirror/addon/search/jump-to-line.js',
'./js/libs/codemirror/addon/search/match-highlighter.js',
'./js/libs/codemirror/addon/search/matchesonscrollbar.css',
'./js/libs/codemirror/addon/search/matchesonscrollbar.js',
'./js/libs/codemirror/addon/search/search.js',
'./js/libs/codemirror/addon/search/searchcursor.js',
'./js/libs/codemirror/mode/javascript.js',
'./js/libs/codemirror/theme/monokai.css',
'./js/libs/signals.min.js',
'./js/libs/ui.js',
'./js/Code.js',
'./js/Config.js',
'./js/Controls.js',
'./js/Editor.js',
'./js/Menubar.js',
'./js/MenubarEdit.js',
'./js/MenubarExamples.js',
'./js/MenubarFile.js',
'./js/MenubarHelp.js',
'./js/Sidebar.js',
'./js/SidebarAnimation.js',
'./js/SidebarProject.js',
'./js/SidebarRender.js',
'./js/Timeline.js',
'./js/TimelineAnimations.js',
'./js/TimelineCurves.js',
'./js/Viewport.js'
];
self.addEventListener( 'install', async function () {
const cache = await caches.open( cacheName );
assets.forEach( function ( asset ) {
cache.add( asset ).catch( function () {
console.warn( '[SW] Cound\'t cache:', asset );
} );
} );
} );
self.addEventListener( 'fetch', async function ( event ) {
const request = event.request;
event.respondWith( networkFirst( request ) );
} );
async function networkFirst( request ) {
return fetch( request ).catch( async function () {
const cachedResponse = await caches.match( request );
if ( cachedResponse === undefined ) {
console.warn( '[SW] Not cached:', request.url );
}
return cachedResponse;
} );
}
/*
async function cacheFirst( request ) {
const cachedResponse = await caches.match( request );
if ( cachedResponse === undefined ) {
console.warn( '[SW] Not cached:', request.url );
return fetch( request );
}
return cachedResponse;
}
*/