chore: enhance PWA cache invalidation logic
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
@@ -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
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user