chore: enhance PWA cache invalidation logic

This commit is contained in:
2026-02-10 17:35:05 +01:00
parent 892ee52efb
commit be82e873cf
2 changed files with 10 additions and 1 deletions

View File

@@ -40,7 +40,11 @@ if ('serviceWorker' in navigator) {
} }
navigator.serviceWorker.addEventListener('controllerchange', triggerReload) navigator.serviceWorker.addEventListener('controllerchange', triggerReload)
const checkForUpdate = () => { const checkForUpdate = () => {
navigator.serviceWorker.getRegistration().then((registration) => registration?.update()) navigator.serviceWorker.getRegistration().then((registration) => {
if (registration) {
registration.update()
}
})
} }
window.addEventListener('visibilitychange', () => { window.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') checkForUpdate() if (document.visibilityState === 'visible') checkForUpdate()

View File

@@ -12,6 +12,11 @@ export default defineConfig({
VitePWA({ VitePWA({
registerType: 'autoUpdate', registerType: 'autoUpdate',
injectRegister: 'auto', injectRegister: 'auto',
workbox: {
cleanupOutdatedCaches: true,
skipWaiting: true,
clientsClaim: true,
},
devOptions: { devOptions: {
enabled: true enabled: true
}, },