-
Notifications
You must be signed in to change notification settings - Fork 0
/
piodide_sw.js
27 lines (26 loc) · 1.25 KB
/
piodide_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
self.addEventListener('install', (event) => {
event.waitUntil(async function () {
const cache = await caches.open('piodide');
await cache.addAll([
'https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.js',
'https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide_py.tar',
'https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.asm.js',
'https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.asm.data',
'https://cdn.jsdelivr.net/pyodide/v0.21.2/full/repodata.json',
'https://cdn.jsdelivr.net/pyodide/v0.21.2/full/pyodide.asm.wasm',
'https://cdn.jsdelivr.net/pyodide/v0.21.2/full/packaging-21.3-py3-none-any.whl',
'https://cdn.jsdelivr.net/pyodide/v0.21.2/full/distutils.tar',
'https://cdn.jsdelivr.net/pyodide/v0.21.2/full/micropip-0.1-py3-none-any.whl',
''
]);
}());
});
self.addEventListener('fetch', (event) => {
event.respondWith(async function () {
const cache = await caches.open('piodide');
const cachedResponse = await cache.match(event.request);
if (cachedResponse) return cachedResponse;
const networkResponse = await fetch(event.request);
return networkResponse;
}());
});