Repository navigation
Expand file tree
/
Copy pathsw.js
More file actions
162 lines (155 loc) · 5.48 KB
/
Copy pathsw.js
File metadata and controls
162 lines (155 loc) · 5.48 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
154
155
156
157
158
159
160
161
162
/**
* THE CIPHER MUSEUM — Service Worker
* Offline support for classrooms and flaky connections.
*
* Strategy:
* - HTML navigations: network-first, falling back to cache (content stays fresh
* online; cached pages may be available offline while their assets remain cached).
* - Static assets (css/js/images/json): cache-first with background refresh.
* - Requests under /public/, including corpus samples and reports, bypass this cache.
*
* VERSION is stamped automatically by `npm run build:js` from a hash of every
* asset served cache-first — the minified bundles, the non-HTML entries of
* CORE below, and the self-contained offline fallback page (scripts/sw-version.js).
* tests/test-sw-version.js fails the suite if it drifts. Old caches are purged
* on activate, so adding an asset to CORE also re-stamps VERSION.
*/
'use strict';
const VERSION = 'cipher-museum-868b5b92';
const CORE = [
'/',
'/index.html',
'/offline.html',
'/ciphers/myszkowski.html',
'/ciphers/turning-grille.html',
'/ciphers/hagelin-c36.html',
'/ciphers/nema.html',
'/ciphers/rs44.html',
'/ciphers/double-playfair.html',
'/ciphers/amsco.html',
'/css/manual-cipher-demos.css',
'/js/manual-cipher-demos.js',
'/css/multiple-anagramming.css',
'/js/multiple-anagramming.js',
'/css/pad-experiments.css',
'/js/pad-experiments.js',
'/css/detective-workspaces.css',
'/js/detective/workspaces.js',
'/js/detective/playback.js',
'/js/detective/lang-model.js',
'/lab/evidence-workbench.html',
'/lab/decipherment-cases.html',
'/lab/modern-attack-evidence.html',
'/ciphers/ua-8295.html',
'/ciphers/sodark.html',
'/ciphers/nfc-deployment.html',
'/css/research-workbench.css',
'/js/research-model.js',
'/js/research-worker.js',
'/js/research-language-model.js',
'/data/research/v1/language-model.json',
'/js/research-ui.js',
'/js/research-cases.js',
'/data/research/v1/z340-section-1.json',
'/js/ciphers/all-engines.min.js',
'/css/museum.css',
'/css/historical-demos.css',
'/js/historical-ciphers.js',
'/js/historical-demos.js',
'/js/nav.js',
'/js/footer.js',
'/js/breadcrumbs.js',
'/js/ui-delegates.js',
'/js/trust-labels.js',
'/js/search.js',
'/js/search-index.json',
'/js/artifact-cards.js',
'/js/artifact-cards-data.min.js',
'/js/demo-loader.min.js',
'/js/lightbox.js',
'/fonts/cinzel-400-latin-ext.woff2',
'/fonts/cinzel-400-latin.woff2',
'/fonts/cinzel-600-latin-ext.woff2',
'/fonts/cinzel-600-latin.woff2',
'/fonts/cinzel-700-latin-ext.woff2',
'/fonts/cinzel-700-latin.woff2',
'/fonts/cormorant-garamond-italic-300-latin-ext.woff2',
'/fonts/cormorant-garamond-italic-300-latin.woff2',
'/fonts/cormorant-garamond-italic-400-latin-ext.woff2',
'/fonts/cormorant-garamond-italic-400-latin.woff2',
'/fonts/cormorant-garamond-italic-600-latin-ext.woff2',
'/fonts/cormorant-garamond-italic-600-latin.woff2',
'/fonts/cormorant-garamond-300-latin-ext.woff2',
'/fonts/cormorant-garamond-300-latin.woff2',
'/fonts/cormorant-garamond-400-latin-ext.woff2',
'/fonts/cormorant-garamond-400-latin.woff2',
'/fonts/cormorant-garamond-600-latin-ext.woff2',
'/fonts/cormorant-garamond-600-latin.woff2',
'/fonts/cormorant-garamond-700-latin-ext.woff2',
'/fonts/cormorant-garamond-700-latin.woff2',
'/fonts/jetbrains-mono-300-latin-ext.woff2',
'/fonts/jetbrains-mono-300-latin.woff2',
'/fonts/jetbrains-mono-400-latin-ext.woff2',
'/fonts/jetbrains-mono-400-latin.woff2',
'/fonts/jetbrains-mono-500-latin-ext.woff2',
'/fonts/jetbrains-mono-500-latin.woff2',
'/fonts/jetbrains-mono-700-latin-ext.woff2',
'/fonts/jetbrains-mono-700-latin.woff2',
'/hall-of-foundations/index.html',
'/hall-of-foundations/foundations.css',
'/images/icons.svg',
'/favicon.svg',
'/manifest.webmanifest',
'/images/icons/icon-192.png',
'/images/icons/icon-512.png'
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(VERSION).then((cache) => cache.addAll(CORE)).then(() => self.skipWaiting())
);
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys()
.then((keys) => Promise.all(keys.filter((k) => k !== VERSION).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;
// Bypass all /public/ requests, including corpus downloads, samples and reports.
if (url.pathname.startsWith('/public/')) return;
if (req.mode === 'navigate') {
// Network-first for pages. An unvisited exhibit must display an explicit
// offline notice, not the homepage at an exhibit URL with broken relative
// assets (or misleading homepage content).
event.respondWith(
fetch(req)
.then((res) => {
const copy = res.clone();
caches.open(VERSION).then((cache) => cache.put(req, copy));
return res;
})
.catch(() => caches.match(req).then((hit) => hit || caches.match('/offline.html')))
);
return;
}
// Cache-first with background refresh for static assets.
event.respondWith(
caches.match(req).then((hit) => {
const refresh = fetch(req)
.then((res) => {
if (res && res.ok) {
const copy = res.clone();
caches.open(VERSION).then((cache) => cache.put(req, copy));
}
return res;
})
.catch(() => hit);
return hit || refresh;
})
);
});