-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathservice-worker.js
128 lines (83 loc) · 2.55 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// update worker name when updating cached files
const WORKER_NAME = 'codeit-worker-v785';
self.importScripts('/worker/client-channel.js');
let WORKER_CACHE_ENABLED = true;
if (isDev) {
WORKER_CACHE_ENABLED = false;
}
// list of files to cache
const FILES_TO_CACHE = [
'/lib/codeit.js',
'/lib/prism.js',
'/lib/plugins/codeit-line-numbers.js',
'/lib/plugins/codeit-match-braces.js',
'/lib/plugins/codeit-autolinker.js',
'/lib/plugins/codeit-autocomplete.js',
'/full',
'/full.css',
'/worker/worker-channel.js',
'/utils.js',
'/manifest.js',
'/files.js',
'/links.js',
'/repos.js',
'/git/gitapi.js',
'/git/gitauth.js',
'/codedrop.js',
'/filebrowser.js',
'/spotlightsearch.js',
'/localstorage.js',
'/bottomfloat.js',
'/context-menu.js',
'/live-view/live-view.js',
'/live-view/extensions/draggable.js',
'/live-view/extensions/beautifier.min.js',
'/live-view/extensions/mobile-console/console-sheet.js',
'/live-view/extensions/mobile-console/logger.js',
'/live-view/extensions/mobile-console/safari-keyboard.js',
'/live-view/extensions/markdown/marked.min.js',
'/live-view/extensions/markdown/markdown-dark.css',
'/editor-theme.css',
'/fonts/fonts.css',
'/fonts/Mono-Sans/MonoSans-Regular.woff2',
'/fonts/Mono-Sans/MonoSans-Italic.woff2',
'/fonts/Mono-Sans/MonoSans-Bold.woff2',
'/fonts/Mono-Sans/MonoSans-BoldItalic.woff2',
'/fonts/Inter/Inter-Regular.woff2',
'/fonts/Inter/Inter-Italic.woff2',
'/fonts/Inter/Inter-Medium.woff2',
'/fonts/Inter/Inter-SemiBold.woff2',
'/fonts/Inter/Inter-SemiBoldItalic.woff2',
'/fonts/Inter/Inter-Bold.woff2',
'/fonts/Roboto-Mono/RobotoMono-Regular.woff2',
'/fonts/Roboto-Mono/RobotoMono-Italic.woff2',
'/fonts/Roboto-Mono/RobotoMono-Bold.woff2',
'/fonts/Roboto-Mono/RobotoMono-BoldItalic.woff2',
'https://plausible.io/js/plausible.js',
'/',
'/icons/android-app-512.png',
'/icons/iphone-app-180.png',
'/icons/app-favicon.png',
'/icons/mac-icon-512-padding.png'
];
// remove previous cached data
caches.keys().then((keyList) => {
return Promise.all(keyList.map((key) => {
if (key !== WORKER_NAME ||
!WORKER_CACHE_ENABLED) {
return caches.delete(key);
}
}));
});
// precache static resources
if (WORKER_CACHE_ENABLED) {
caches.open(WORKER_NAME).then((cache) => {
return cache.addAll(FILES_TO_CACHE);
});
}
self.addEventListener('install', (evt) => {
self.skipWaiting();
});
self.addEventListener('activate', (evt) => {
self.clients.claim();
});