PWA-Unterstützung hinzugefügt: manifest.webmanifest, Service Worker, Installierbarkeit auf Homescreen/Desktop
This commit is contained in:
39
static/sw.js
Normal file
39
static/sw.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const CACHE_NAME = 'wordle-cheater-v1';
|
||||
const APP_SHELL = [
|
||||
'/',
|
||||
'/static/favicon.svg',
|
||||
];
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL))
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((keys) => Promise.all(
|
||||
keys.map((k) => (k === CACHE_NAME ? null : caches.delete(k)))
|
||||
))
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
const { request } = event;
|
||||
// Netzwerk zuerst für HTML, sonst Cache-First
|
||||
if (request.mode === 'navigate') {
|
||||
event.respondWith(
|
||||
fetch(request).catch(() => caches.match('/'))
|
||||
);
|
||||
return;
|
||||
}
|
||||
event.respondWith(
|
||||
caches.match(request).then((cached) =>
|
||||
cached || fetch(request).then((resp) => {
|
||||
const copy = resp.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(request, copy));
|
||||
return resp;
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
Reference in New Issue
Block a user