Bug 332455
| Summary: | Service worker soft update never hits the HTTP cache on macOS | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Gregory Mitchell <me> |
| Component: | New Bugs | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW | ||
| Severity: | Normal | CC: | webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Safari 26 | ||
| Hardware: | Mac (Apple Silicon) | ||
| OS: | macOS 26 | ||
On macOS, WebKit sends an unconditional network request for the service worker script after every document navigation, even when the script is served with
Cache-Control: max-age=86400and the registration usesupdateViaCache: 'all'.The request is a full 200 each time. On Linux with a persistent profile the same page does not make this kind of request.
Steps to Reproduce
Serve a page that registers a service worker with:
/sw.jswithCache-Control: max-age=86400and log every request that reaches the server.Expected
Inside the script's freshness lifetime the soft update is answered from the cache, so the server sees no request for /sw.js.
Actual
The server sees one GET
/sw.jsabout one second after each document navigation: 6 of 6 navigations and 3 of 3 new tabs on macOS in Playwright's WebKit with a persistent profile, and 4 requests for 3 navigations and one reload in Safari 26.5.2. The count is the same at script lifetimes of 2, 6 and 20 seconds and one day. Navigations under a second apart share one request, because the soft update timer is one second and ignores navigations while it runs. Linux with a persistent profile makes 0. An explicitregistration.update()called from the page does hit the cache on macOS.Additional Information
Read at WebKit main,
eb96cf53cad2f39d67ffd557e91d7e6a91d5bcc4; Playwright's WebKit build may differ from it, so each claim is paired with the counts above. Page requests are keyed with a cache partition equal to the host (SecurityOrigin::domainForCachePartition). The soft update request is built without a partition (SWServer::createScriptRequest). The cache key includes the partition (NetworkCache::Cache::makeCacheKey), so the lookup for the script cannot match an entry stored under a partitioned key. The soft update loader never stores what it fetches (ServiceWorkerSoftUpdateLoader.cpphas no store call), so nothing can fill the unpartitioned key either.Import Scripts
A worker whose main script is a small importScripts('<core URL>') shim, with the core at an immutable URL (
Cache-Control: public, max-age=31536000, immutable), still gets the core re-fetched in full on every document navigation. Playwright WebKit 27.2 on macOS, persistent profile, five navigations at 1.5 s, two runs. The server saw one GET for the shim and one GET for the core per navigation, each core a 200 with the full 134,609-byte body (5 of 5 navigations, both runs). No conditional headers on any request.Chromium 156 and Firefox 157 fetched the core once, with the install, and nothing after it in the same runs.
The core fetch during a soft update does not change the running worker unless the main script changes. When the core changed on the server with the main script byte-identical, WebKit kept running the old core for every navigation, even though it fetched the new content on each navigation. A changed core under an unchanged main script is not an update. Source reading is that the imports of a soft update use the same uncached path as the main script. The probe shows the behaviour, not the cause.