diff --git a/manifest.json b/manifest.json index 467ef65..0fd3ae1 100755 --- a/manifest.json +++ b/manifest.json @@ -1,9 +1,11 @@ { - "name": "DoMiLi", + "name": "DoMiLi - Dönerstag-Runde", "short_name": "DoMiLi", - "description": "Dönerstag-Runde", - "start_url": "index.php", + "description": "Die Dönerstag-Runde des Domili Treffs", + "start_url": "/", + "scope": "./", "display": "standalone", + "orientation": "portrait", "theme_color": "#212529", "background_color": "#212529", "icons": [ @@ -16,6 +18,17 @@ "src": "img/icon-512.png", "sizes": "512x512", "type": "image/png" + }, + { + "src": "img/icon-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" } - ] + ], + "serviceworker": { + "src": "sw.js", + "scope": "/", + "update_via_cache": "none" + } } \ No newline at end of file diff --git a/offline.html b/offline.html new file mode 100755 index 0000000..51512e7 --- /dev/null +++ b/offline.html @@ -0,0 +1,65 @@ + + + + + + DoMiLi - Offline + + + + + + + + + +
+
+
+
+
+
+
+ cloud_off +
+

Keine Internetverbindung

+

+ Bitte überprüfe deine Netzwerkverbindung und versuche es erneut. +

+
+ +
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/sw.js b/sw.js new file mode 100755 index 0000000..dd5faed --- /dev/null +++ b/sw.js @@ -0,0 +1,77 @@ +const CACHE_NAME = 'domili-v' + new Date().getTime(); +const urlsToCache = [ + '/', + //'/index.php', + //'/login.php', + '/offline.html', + '/css/style.css', + '/img/icon-192.png', + '/img/icon-512.png' +]; + +// Installation - immer neue Version +self.addEventListener('install', event => { + event.waitUntil( + caches.open(CACHE_NAME) + .then(cache => { + return cache.addAll(urlsToCache); + }) + ); + self.skipWaiting(); // Sofort aktivieren +}); + +// Aktivierung - alte Caches automatisch löschen +self.addEventListener('activate', event => { + event.waitUntil( + caches.keys().then(cacheNames => { + return Promise.all( + cacheNames + .filter(name => name !== CACHE_NAME) + .map(name => caches.delete(name)) + ); + }) + ); + return self.clients.claim(); // Sofort Kontrolle übernehmen +}); + +// Fetch mit Network First für PHP, Cache First für statische Dateien +self.addEventListener('fetch', event => { + if (!event.request.url.startsWith('http')) return; + + const url = new URL(event.request.url); + + // Statische Ressourcen - Cache First + if (url.pathname.endsWith('.css') || + url.pathname.endsWith('.png') || + url.pathname.endsWith('.jpg') || + url.pathname.endsWith('.js')) { + event.respondWith( + caches.match(event.request) + .then(response => response || fetch(event.request)) + ); + } + // Dynamische Seiten - Network First mit Offline-Fallback + else { + event.respondWith( + fetch(event.request) + .then(response => { + // Bei erfolgreicher Antwort: in Cache speichern + if (response && response.status === 200) { + const responseToCache = response.clone(); + caches.open(CACHE_NAME).then(cache => { + cache.put(event.request, responseToCache); + }); + } + return response; + }) + .catch(() => caches.match('/offline.html')) + ); + } +}); + +// Nachrichten vom Client empfangen +self.addEventListener('message', event => { + if (event.data.action === 'skipWaiting') { + self.skipWaiting(); + } +}); \ No newline at end of file