demo · v140
Cold-boot Race
The motivating cost: when a navigation lands and the service worker is cold-started, the browser used to wait for SW startup before issuing the network request. AutoPreload fires the request in parallel — if the fetch handler calls respondWith() the SW response wins, otherwise the network response goes straight through. Drag the sliders to see the timeline.
time (ms) →
no preload
with autopreload
SW bootstrap
network fetch
respondWith() / handing back
first byte — no preload
— ms
first byte — autopreload
— ms
// HTTP response header — Chrome 140+
Service-Worker-Auto-Preload: true
// or via the proposed enterprise policy / origin trial
// the SW does not change — fetch handler logic is the same.
self.addEventListener("fetch", (event) => {
if (event.request.url.endsWith(".json")) {
event.respondWith(cacheFirst(event.request)); // SW wins
}
// anything else falls through to the preloaded network response
});