Repository navigation
Expand file tree
/
Copy pathsw.js
More file actions
153 lines (144 loc) · 5.1 KB
/
Copy pathsw.js
File metadata and controls
153 lines (144 loc) · 5.1 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* Service worker — GENERATED by tools/build-sw.mjs. Do not edit by hand.
*
* Ritual makes no network requests once it has loaded, so it is a natural fit
* for working offline: precache everything, then serve from the cache.
*
* The one thing to get right is staleness. `index.html` is fetched
* network-first, so a deploy is picked up on the next online load and a stale
* cache can always correct itself. Everything else is cache-first, keyed to a
* version derived from the contents of every file — so a changed asset means a
* new cache name, and the old one is deleted on activate.
*/
const VERSION = '3a80b76aa37e';
const CACHE = `ritual-${VERSION}`;
const PRECACHE = [
"./apple-touch-icon.png",
"./assets/fonts/architectsdaughter-YbvTYlg4w.woff2",
"./assets/fonts/architectsdaughter-bvTYdg4zg.woff2",
"./assets/fonts/caveat-2Q7aDYYmg8.woff2",
"./assets/fonts/caveat-fYB2Q7ZjYY.woff2",
"./assets/fonts/cedarvillecursive-ABnuIrpw.woff2",
"./assets/fonts/cormorantgaramond-WMhyjYqXtK.woff2",
"./assets/fonts/cormorantgaramond-yjYp3tKgS4.woff2",
"./assets/fonts/dancingscript-ViszLgiuE.woff2",
"./assets/fonts/dancingscript-szLuiuEViw.woff2",
"./assets/fonts/ebgaramond-5GR7SDktYw.woff2",
"./assets/fonts/ebgaramond-7e8QL99U6g.woff2",
"./assets/fonts/ebgaramond-F1K5GR1SDk.woff2",
"./assets/fonts/ebgaramond-QL9zU6ingQ.woff2",
"./assets/fonts/gloriahallelujah-MIS71zO0vg.woff2",
"./assets/fonts/gloriahallelujah-bWMIS11zM.woff2",
"./assets/fonts/homemadeapple-ZJob0x6XHg.woff2",
"./assets/fonts/justanotherhand-Ofr2DGiVSw.woff2",
"./assets/fonts/justanotherhand-yOpOfr4DGg.woff2",
"./assets/fonts/kalam-GjLCkiQ4tg.woff2",
"./assets/fonts/kalam-MthfOCfzsw.woff2",
"./assets/fonts/kalam-kDdMthROCc.woff2",
"./assets/fonts/kalam-tD6GjLMkiQ.woff2",
"./assets/fonts/labelleaurore-eI4Eu2EBVk.woff2",
"./assets/fonts/labelleaurore-ovHeI4HO2E.woff2",
"./assets/fonts/mrssaintdelafield-62QKcnLub.woff2",
"./assets/fonts/mrssaintdelafield-WC62QKknLw.woff2",
"./assets/fonts/petitformalscript-5qkHDgPrgZ.woff2",
"./assets/fonts/petitformalscript-RP5qkH7gPg.woff2",
"./assets/fonts/reeniebeanie-uvWxXPq1qw.woff2",
"./assets/fonts/rougescript-Ep3S4Ua.woff2",
"./assets/fonts/shadowsintolighttwo-NmpALHGYNn.woff2",
"./assets/fonts/shadowsintolighttwo-syNmpAzHGQ.woff2",
"./assets/textures/crease-heavy.jpg",
"./assets/textures/crease.jpg",
"./assets/textures/paper-creased.jpg",
"./assets/textures/parchment.jpg",
"./assets/textures/wood-desk.jpg",
"./assets/textures/wood-frame.jpg",
"./favicon.svg",
"./icon-192.png",
"./icon-512.png",
"./index.html",
"./manifest.webmanifest",
"./src/audio/core.js",
"./src/audio/index.js",
"./src/audio/music.js",
"./src/audio/weather.js",
"./src/audio/writing.js",
"./src/core/assets.js",
"./src/core/noise.js",
"./src/core/util.js",
"./src/intensity.js",
"./src/main.js",
"./src/scene/atmos.js",
"./src/scene/burn.js",
"./src/scene/candle.js",
"./src/scene/glass.js",
"./src/scene/lighting.js",
"./src/scene/props.js",
"./src/scene/sky.js",
"./src/scene/textures.js",
"./src/storm-events.js",
"./src/ui/debug.js",
"./src/ui/desk.js",
"./src/ui/haptics.js",
"./src/ui/panels.js",
"./src/ui/seal-art.js",
"./src/ui/seal.js",
"./src/write/hands.js",
"./src/write/paper.js",
"./styles/base.css",
"./styles/fonts.css",
"./styles/paper.css",
"./styles/scene.css",
"./styles/ui.css"
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE)
// Individually, so one failed asset cannot fail the whole install.
.then((cache) => Promise.all(
PRECACHE.map((url) => cache.add(url).catch(() => {}))
))
.then(() => self.skipWaiting())
);
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys()
.then((keys) => Promise.all(
keys.filter((k) => k.startsWith('ritual-') && k !== CACHE)
.map((k) => caches.delete(k))
))
.then(() => self.clients.claim())
);
});
self.addEventListener('fetch', (event) => {
const req = event.request;
if (req.method !== 'GET') return;
const url = new URL(req.url);
if (url.origin !== self.location.origin) return;
// The document is network-first: it is the only file that can tell the
// browser about a new version, so it must never be pinned.
const isDocument = req.mode === 'navigate' ||
(req.headers.get('accept') || '').includes('text/html');
if (isDocument) {
event.respondWith(
fetch(req)
.then((res) => {
const copy = res.clone();
caches.open(CACHE).then((c) => c.put(req, copy)).catch(() => {});
return res;
})
.catch(() => caches.match(req).then((r) => r || caches.match('./index.html')))
);
return;
}
// Everything else is content the version already accounts for.
event.respondWith(
caches.match(req).then((hit) => hit || fetch(req).then((res) => {
if (res && res.ok && res.type === 'basic') {
const copy = res.clone();
caches.open(CACHE).then((c) => c.put(req, copy)).catch(() => {});
}
return res;
}))
);
});