Installable as an app (PWA): manifests, offline-only service worker, icons

This commit is contained in:
Astra 2026-10-03 12:22:33 +01:00
parent b26360e8f3
commit 44708d5f3c
16 changed files with 246 additions and 0 deletions

23
internal/web/assets/sw.js Normal file
View file

@ -0,0 +1,23 @@
// The service worker is what lets the site be installed as an app. It caches nothing but the
// offline page: every request still goes to the network, so nobody sees stale bans or ranks.
const CACHE = "offline-v1";
const OFFLINE = "/static/offline.html";
self.addEventListener("install", (e) => {
e.waitUntil(caches.open(CACHE).then((c) => c.add(OFFLINE)).then(() => self.skipWaiting()));
});
self.addEventListener("activate", (e) => {
e.waitUntil(
caches.keys()
.then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
.then(() => self.clients.claim()),
);
});
// Only page loads get the offline page; API calls fail as they always have, and the pages say so.
self.addEventListener("fetch", (e) => {
if (e.request.mode !== "navigate") return;
e.respondWith(fetch(e.request).catch(() => caches.match(OFFLINE)));
});