hinzugefügt: Grund für Tausch + Discord benachrichtigung + PWA
This commit is contained in:
1 parent
dae99a0b76
commit
497faa72db
8 files changed
+175
-48
No files matched your search
+62
-9
@@ -1,23 +1,76 @@
|
||||
const CACHE_NAME = "whopays-cache-v1";
|
||||
const URLS_TO_CACHE = [
|
||||
const CACHE_NAME = "whopays-v1";
|
||||
const urlsToCache = [
|
||||
"/",
|
||||
"/index.html",
|
||||
"/style.css",
|
||||
"/script.js"
|
||||
"/script.js",
|
||||
"/img/a.png",
|
||||
"/img/b.png",
|
||||
"/img/bgA.jpg",
|
||||
"/img/bgB.jpg",
|
||||
"/manifest.json"
|
||||
];
|
||||
|
||||
self.addEventListener("install", event => {
|
||||
// Install event - cache assets
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then(cache => {
|
||||
return cache.addAll(URLS_TO_CACHE);
|
||||
caches.open(CACHE_NAME).then((cache) => {
|
||||
console.log("Cache geöffnet");
|
||||
return cache.addAll(urlsToCache).catch(err => {
|
||||
console.error("Cache fehler:", err);
|
||||
});
|
||||
})
|
||||
);
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", event => {
|
||||
// Activate event - clean old caches
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((cacheNames) => {
|
||||
return Promise.all(
|
||||
cacheNames.map((cacheName) => {
|
||||
if (cacheName !== CACHE_NAME) {
|
||||
console.log("Alte Cache löschen:", cacheName);
|
||||
return caches.delete(cacheName);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
self.clients.claim();
|
||||
});
|
||||
|
||||
// Fetch event - serve from cache, fallback to network
|
||||
self.addEventListener("fetch", (event) => {
|
||||
// Network first for API calls
|
||||
if (event.request.url.includes("/status") ||
|
||||
event.request.url.includes("/toggle")) {
|
||||
event.respondWith(
|
||||
fetch(event.request).catch(() => {
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Offline" }),
|
||||
{ headers: { "Content-Type": "application/json" } }
|
||||
);
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Cache first for static assets
|
||||
event.respondWith(
|
||||
caches.match(event.request).then(response => {
|
||||
return response || fetch(event.request);
|
||||
caches.match(event.request).then((response) => {
|
||||
return response || fetch(event.request).then((fetchResponse) => {
|
||||
return caches.open(CACHE_NAME).then((cache) => {
|
||||
cache.put(event.request, fetchResponse.clone());
|
||||
return fetchResponse;
|
||||
});
|
||||
});
|
||||
}).catch(() => {
|
||||
// Fallback for navigation requests
|
||||
if (event.request.mode === 'navigate') {
|
||||
return caches.match('/index.html');
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user