Files
michaelschiemer/resources/js/serviceWorker.js

24 lines
963 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.
export function registerServiceWorker() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(reg => {
console.log('✅ Service Worker registriert:', reg.scope);
// Update found?
reg.onupdatefound = () => {
const installing = reg.installing;
installing.onstatechange = () => {
if (installing.state === 'installed') {
if (navigator.serviceWorker.controller) {
console.log('🔄 Neue Version verfügbar Seite neu laden?');
} else {
console.log('✅ Inhalte jetzt offline verfügbar');
}
}
};
};
})
.catch(err => console.error('❌ SW-Fehler:', err));
}
}