demo · v131
ServiceWorker auto-preload (browser mode)
Without auto-preload the browser waits for the service worker fetch handler to fetch() before any byte hits the wire. With browser-mode auto-preload the network request fires in parallel to SW boot. Drag the SW startup cost and see the TTFB delta.
without auto-preload
SW boot
network
render
with auto-preload (browser mode)
SW boot
network
render
SW boot
network
render
the api
// Chrome 131 - opt-in via response header on the SW script
Service-Worker-Allowed: /
Speculation-Rules: ... // optional pairing
// Or via navigator.serviceWorker registration option (forthcoming)
await navigator.serviceWorker.register("/sw.js", { type: "module" });