Weekly puzzle: Sunday 06:00 Berlin weeks, published puzzle fetched when Puzzles opens, seeded fallback, countdown and door badge
This commit is contained in:
parent
946da17c8b
commit
34b72f6d44
13 changed files with 307 additions and 13 deletions
|
|
@ -25,6 +25,12 @@ self.addEventListener('fetch', (e) => {
|
|||
}
|
||||
const local = url.origin === location.origin, fonts = /fonts\.(googleapis|gstatic)\.com$/.test(url.hostname);
|
||||
if (!local && !fonts) return;
|
||||
// Weekly puzzles are published between releases: ask the network first, and keep a copy for playing offline.
|
||||
if (local && url.pathname.startsWith('/puzzles/weekly/')) {
|
||||
e.respondWith(fetch(req).then((r) => { if (r.ok) { const copy = r.clone(); caches.open(CACHE).then((c) => c.put(req, copy)); } return r; })
|
||||
.catch(() => caches.match(req).then((r) => r || Response.error())));
|
||||
return;
|
||||
}
|
||||
e.respondWith(caches.open(CACHE).then((c) => c.match(req).then((hit) => {
|
||||
const net = fetch(req).then((r) => { if (r && (r.ok || r.type === 'opaque')) c.put(req, r.clone()); return r; }).catch(() => hit);
|
||||
return hit || net;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue