Files
dickendock/frontend/public/sw.js

28 lines
760 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Service Worker erkennt neue Builds und lädt automatisch neu
// BUILD_TIME wird beim Deploy vom Backend via /api/build-time geliefert
const CACHE_NAME = 'dickendock-v1';
self.addEventListener('install', () => {
self.skipWaiting(); // sofort aktivieren
});
self.addEventListener('activate', e => {
// Alte Caches löschen
e.waitUntil(
caches.keys()
.then(keys => Promise.all(keys.map(k => caches.delete(k))))
.then(() => self.clients.claim())
);
});
// Alle Requests direkt ans Netzwerk kein Caching
self.addEventListener('fetch', e => {
e.respondWith(fetch(e.request));
});
// Auf Update-Nachricht vom Frontend reagieren
self.addEventListener('message', e => {
if (e.data === 'SKIP_WAITING') self.skipWaiting();
});