Weekly puzzle: Sunday 06:00 Berlin weeks, published puzzle fetched when Puzzles opens, seeded fallback, countdown and door badge

This commit is contained in:
Frederic Jung 2026-10-28 20:42:37 +01:00
parent 946da17c8b
commit 34b72f6d44
No known key found for this signature in database
13 changed files with 307 additions and 13 deletions

View file

@ -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;