how to update sw.js
in production?
#768
-
i had some mistakes for my prior auto-generated i need to update the production version of i need a possibility to set if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js', {
updateViaCache: 'all',
});
} i've already take a look on vite-pwa // register the service worker
wb.register({ immediate }).then((r) => {
if (onRegisteredSW)
onRegisteredSW('__SW__', r)
else
onRegistered?.(r)
}).catch((e) => {
onRegisterError?.(e)
}) but, its already registered with where should i put references: https://developer.chrome.com/blog/fresher-sw/#updateviacache |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
i'm just read https://developer.chrome.com/docs/workbox/modules/workbox-window#when_an_updated_version_of_the_service_worker_is_found and, i think i need to manually triggering update checks navigator.serviceWorker.ready.then((registration) => {
registration.update();
}); but, where should i put it to? |
Beta Was this translation helpful? Give feedback.
-
i use Astro version v2.10.15
Package manager pnpm
Platform darwin
Architecture arm64
Adapter Couldn't determine.
Integrations astro-i18next, astro-imagetools, @storyblok/astro, @astrojs/tailwind, @astrojs/sitemap, astro-robots-txt, @astrojs/partytown, @vite-pwa/astro-integration, astro-compress, astro-critters and now, i end up put it to my import { registerSW } from "virtual:pwa-register"
registerSW({
immediate: true,
onNeedRefresh: () => {
navigator.serviceWorker.ready.then((registration) => {
registration.update()
})
}
}) reference: https://vite-pwa-org.netlify.app/frameworks/astro.html#auto-update any helps very appreciated 🙏 |
Beta Was this translation helpful? Give feedback.
You can destroy your service worker and include a new one: check this guide https://vite-pwa-org.netlify.app/guide/unregister-service-worker.html
Read the page and ask if you need help, ping me on discord server here (pwa channel): https://discord.gg/BFrgqvVV