Does Service Worker registration.update called for client side navigation?
#14341
|
Does It might be helpful to mention this behavior in the SvelteKit Service Workers documentation: https://svelte.dev/docs/kit/service-workers |
Replies: 1 comment 2 replies
|
No. Client-side navigations don't trigger an update check, neither from the browser nor from SvelteKit. Browsers check for a new worker on full-page navigations within scope and on functional events like push and sync, and an SPA route change is neither. SvelteKit itself calls So yes, if you want the worker to pick up new versions as users navigate, trigger it yourself: import { afterNavigate } from '$app/navigation';
afterNavigate(() => {
navigator.serviceWorker?.getRegistration().then((r) => r?.update());
});Agreed this belongs on the service workers docs page, I'm happy to send a docs PR for it. |
No. Client-side navigations don't trigger an update check, neither from the browser nor from SvelteKit. Browsers check for a new worker on full-page navigations within scope and on functional events like push and sync, and an SPA route change is neither. SvelteKit itself calls
registration.update()in exactly two places, and both are error recovery rather than routine navigation. When a route module fails to load, or a navigation lands on a 400+ status, kit asks its version poller whether a new deployment happened, updates the service worker if so, and then falls back to a full-page navigation anyway.So yes, if you want the worker to pick up new versions as users navigate, trigger it you…