feat: add app icons and PWA shell
CI / test (push) Successful in 2m40s

This commit is contained in:
strsv committed 2026-11-06 08:27:02 +03:00
1 parent 2fcb29e3fe
commit 97a5098511
23 files changed
+146 -57

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
const CACHE = "steambase-shell-v1";
const SHELL = [
"/",
"/static/styles.css",
"/static/app.js",
"/static/icon-192.png",
"/static/site.webmanifest",
];
self.addEventListener("install", (event) => {
event.waitUntil(
caches.open(CACHE).then((cache) => cache.addAll(SHELL)).then(() => self.skipWaiting())
);
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches.keys()
.then((keys) => Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key))))
.then(() => self.clients.claim())
);
});
self.addEventListener("fetch", (event) => {
const request = event.request;
const url = new URL(request.url);
if (request.method !== "GET" || url.origin !== self.location.origin) return;
if (url.pathname.startsWith("/api/")) return;
if (request.mode === "navigate") {
event.respondWith(fetch(request).catch(() => caches.match("/")));
return;
}
event.respondWith(
fetch(request)
.then((response) => {
if (response.ok) {
const copy = response.clone();
caches.open(CACHE).then((cache) => cache.put(request, copy));
}
return response;
})
.catch(() => caches.match(request))
);
});