-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathservice-worker.js
62 lines (51 loc) · 1.87 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
const cacheName = "cache-v3";
self.addEventListener('install', e => {
e.waitUntil(
caches.open(cacheName).then(cache => {
cache.addAll([
"/",
"/index.html",
"/dist/editor.bundle.js",
"/css/style.css",
"/css/editor.css",
"/media/App-Icon.png",
"/media/favicon.ico",
"/media/file.svg",
"/media/psc.svg",
"/media/desktop.png",
"/media/phone.png",
"/fonts/SF-Pro-Display-Regular.otf",
"/PS2/main.py",
"/PS2/ps2/__init__.py",
"/PS2/ps2/app.py",
"/PS2/ps2/expr/__init__.py",
"/PS2/ps2/expr/expression.py",
"/PS2/ps2/interpret/__init__.py",
"/PS2/ps2/interpret/interpretor.py",
"/PS2/ps2/parser/__init__.py",
"/PS2/ps2/parser/parser.py",
"/PS2/ps2/scan/__init__.py",
"/PS2/ps2/scan/ps2_token.py",
"/PS2/ps2/scan/scanner.py",
"/PS2/ps2/statement/__init__.py",
"/PS2/ps2/statement/statement.py",
"/PS2/ps2/symbol_table/__init__.py",
"/PS2/ps2/symbol_table/environment.py",
"/PS2/ps2/utilities.py"
])
.then(() => {console.log("Cached files!")})
})
);
});
self.addEventListener('fetch', e => {
e.respondWith((async () => {
const r = await caches.match(e.request.url);
if (r && !navigator.onLine) return r;
const response = await fetch(e.request);
if (e.request.url.startsWith('http')) {
const cache = await caches.open(cacheName);
await cache.put(e.request.url, response.clone());
}
return response;
})());
});