Force PWA updates before push registration

This commit is contained in:
Dorian
2026-05-15 14:31:55 -05:00
parent 8e2136f304
commit be69dd97e7
3 changed files with 19 additions and 3 deletions

View File

@@ -6,8 +6,17 @@ createApp(App).mount('#app')
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js').catch((error) => {
navigator.serviceWorker.register('/sw.js', { updateViaCache: 'none' }).then((registration) => {
registration.update().catch(() => {})
}).catch((error) => {
console.warn('Service worker registration failed:', error)
})
})
let refreshing = false
navigator.serviceWorker.addEventListener('controllerchange', () => {
if (refreshing) return
refreshing = true
window.location.reload()
})
}