Weise dem Web-App-Manifest den richtigen MIME-Typ zu und registriere einen Service Worker, damit Browser und Handy die Installation anbieten.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
339238ce21
commit
db4063296b
5 files changed
+83
No files matched your search
@@ -2,6 +2,7 @@
|
||||
"name": "Tsumugu",
|
||||
"short_name": "Tsumugu",
|
||||
"description": "Unterlagen im Zusammenhang ordnen und wiederfinden.",
|
||||
"id": "/",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
const CACHE = "tsumugu-shell-v1";
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(
|
||||
caches
|
||||
.open(CACHE)
|
||||
.then((cache) => cache.add("/"))
|
||||
.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;
|
||||
if (request.method !== "GET" || request.headers.has("range")) return;
|
||||
|
||||
const url = new URL(request.url);
|
||||
if (url.origin !== self.location.origin) return;
|
||||
if (url.pathname.startsWith("/api/") || url.pathname.startsWith("/health")) return;
|
||||
if (url.pathname === "/sw.js" || url.pathname === "/manifest.webmanifest") return;
|
||||
|
||||
if (request.mode === "navigate") {
|
||||
event.respondWith(networkFirstNavigation(request));
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.pathname.startsWith("/assets/")) {
|
||||
event.respondWith(cacheFirst(request));
|
||||
}
|
||||
});
|
||||
|
||||
async function networkFirstNavigation(request) {
|
||||
const cache = await caches.open(CACHE);
|
||||
try {
|
||||
const response = await fetch(request);
|
||||
if (response.ok && response.type === "basic") await cache.put("/", response.clone());
|
||||
return response;
|
||||
} catch (error) {
|
||||
const cached = await cache.match("/");
|
||||
if (cached) return cached;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function cacheFirst(request) {
|
||||
const cache = await caches.open(CACHE);
|
||||
const cached = await cache.match(request);
|
||||
if (cached) return cached;
|
||||
const response = await fetch(request);
|
||||
if (response.ok && response.type === "basic") await cache.put(request, response.clone());
|
||||
return response;
|
||||
}
|
||||
Reference in new issue
Block a user