feat: add pwa support

This commit is contained in:
Your Name
2025-10-13 22:48:34 -06:00
parent e333121999
commit d58c0723b1
6 changed files with 94 additions and 1 deletions

56
service-worker.js Normal file
View File

@@ -0,0 +1,56 @@
const CACHE_NAME = 'weltzeit-cache-v1';
const PRECACHE_RESOURCES = [
'./',
'./index.html',
'./styles.css',
'./app.js',
'./zones.js',
'./manifest.webmanifest',
'./icons/icon-192.png',
'./icons/icon-512.png'
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(PRECACHE_RESOURCES))
);
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((cacheNames) =>
Promise.all(
cacheNames.map((cacheName) => {
if (cacheName !== CACHE_NAME) {
return caches.delete(cacheName);
}
return undefined;
})
)
)
);
});
self.addEventListener('fetch', (event) => {
if (event.request.method !== 'GET') {
return;
}
event.respondWith(
caches.match(event.request).then((cachedResponse) => {
if (cachedResponse) {
return cachedResponse;
}
return fetch(event.request)
.then((response) => {
const responseClone = response.clone();
caches.open(CACHE_NAME).then((cache) => {
cache.put(event.request, responseClone);
});
return response;
})
.catch(() => caches.match('./index.html'));
})
);
});