Repository navigation
Expand file tree
/
Copy pathsw.js
More file actions
86 lines (83 loc) · 2.38 KB
/
Copy pathsw.js
File metadata and controls
86 lines (83 loc) · 2.38 KB
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
/* Farbklecks – Service Worker: keeps the whole app on the device so it runs without internet. */
const CACHE = 'farbklecks-v2';
const ASSETS = [
'./',
'./index.html',
'./css/base.css',
'./css/paint.css',
'./css/screens.css',
'./css/trace.css',
'./css/dots.css',
'./css/read.css',
'./js/core/util.js',
'./js/core/store.js',
'./js/core/sound.js',
'./js/data/colors.js',
'./js/data/stickers.js',
'./js/art/dsl.js',
'./js/art/tiere.js',
'./js/art/tiere2.js',
'./js/art/schweiz.js',
'./js/art/schweiz2.js',
'./js/art/fahrzeuge.js',
'./js/art/fahrzeuge2.js',
'./js/art/fantasie.js',
'./js/art/fantasie2.js',
'./js/art/natur.js',
'./js/art/preview.js',
'./js/learn/glyphs.js',
'./js/learn/words.js',
'./js/learn/dots.js',
'./js/paint/brushes.js',
'./js/paint/engine.js',
'./js/ui/fx.js',
'./js/ui/ui.js',
'./js/ui/pencils.js',
'./js/screens/hub.js',
'./js/screens/book.js',
'./js/screens/color.js',
'./js/screens/free.js',
'./js/screens/gallery.js',
'./js/screens/album.js',
'./js/screens/trace.js',
'./js/screens/dots.js',
'./js/screens/read.js',
'./js/app.js',
'./fonts/andika-400.woff2',
'./fonts/andika-700.woff2',
'./fonts/baloo2.woff2',
'./manifest.webmanifest',
'./icons/icon.svg',
'./icons/icon-192.png',
'./icons/icon-512.png',
'./icons/icon-maskable-512.png',
'./icons/apple-touch-icon.png',
];
self.addEventListener('install', (event) => {
event.waitUntil(caches.open(CACHE).then((c) => c.addAll(ASSETS.map((u) => new Request(u, { cache: 'reload' })))).then(() => self.skipWaiting()));
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys()
.then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
.then(() => self.clients.claim())
);
});
self.addEventListener('fetch', (event) => {
const req = event.request;
if (req.method !== 'GET' || new URL(req.url).origin !== self.location.origin) return;
event.respondWith(
caches.match(req, { ignoreSearch: true }).then((hit) => {
if (hit) return hit;
return fetch(req)
.then((res) => {
if (res.ok) {
const copy = res.clone();
caches.open(CACHE).then((c) => c.put(req, copy));
}
return res;
})
.catch(() => (req.mode === 'navigate' ? caches.match('./index.html') : Response.error()));
})
);
});