feat: Add WFW-Aushang web app with PWA support, offline caching, and dark mode
- Created index.html for the main application interface with responsive design and dark mode support. - Added manifest.webmanifest for PWA configuration, including app icons and display settings. - Implemented service worker (sw.js) for offline caching of assets and network-first strategy for versioning. - Introduced version.json to manage app versioning.
This commit is contained in:
68
bibel-pwa/service-worker.js
Normal file
68
bibel-pwa/service-worker.js
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Service Worker für die Bibel Lern‑App
|
||||
* Dieser Worker sorgt dafür, dass die wesentlichen Dateien
|
||||
* für den Offline‑Betrieb zwischengespeichert werden und
|
||||
* veraltetete Caches bereinigt werden.
|
||||
*/
|
||||
|
||||
const CACHE_NAME = 'bibel-app-cache-v3';
|
||||
// Arbeite mit relativen Pfaden, damit die PWA auch aus einem Unterordner funktioniert.
|
||||
const BASE_PATH = new URL(self.registration.scope).pathname.replace(/\/$/, '');
|
||||
const scopePath = (path) => `${BASE_PATH}/${path}`;
|
||||
const OFFLINE_URLS = [
|
||||
'index.html',
|
||||
'styles.css',
|
||||
'script.js',
|
||||
'manifest.json',
|
||||
'data.json',
|
||||
'data.csv',
|
||||
'icon-192x192.png',
|
||||
'icon-512x512.png'
|
||||
].map(scopePath);
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => {
|
||||
return cache.addAll(OFFLINE_URLS);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((cacheNames) => {
|
||||
return Promise.all(
|
||||
cacheNames.map((cacheName) => {
|
||||
if (cacheName !== CACHE_NAME) {
|
||||
return caches.delete(cacheName);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
if (event.request.method !== 'GET') return;
|
||||
const requestUrl = new URL(event.request.url);
|
||||
|
||||
// Nur Anfragen innerhalb des eigenen Ursprungs beantworten, damit Offsite‑Requests
|
||||
// nicht ungewollt überschrieben werden.
|
||||
if (requestUrl.origin !== self.location.origin) return;
|
||||
|
||||
event.respondWith(
|
||||
caches.match(event.request).then((cached) => {
|
||||
if (cached) return cached;
|
||||
return fetch(event.request).catch(() => {
|
||||
// Fallback bei HTML‑Anfragen
|
||||
if (
|
||||
event.request.mode === 'navigate' ||
|
||||
event.request.headers.get('accept')?.includes('text/html')
|
||||
) {
|
||||
return caches.match(scopePath('index.html'));
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user