You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: Serve immutable files from the service worker cache first - #1096
The PWA service worker was network-first for every request, including the files that never change. It fell back to its cache only when fetch() rejected before the response headers arrived, so a connection reset mid-body reached the app even with everything cached. It also registered right after runMain, and its install downloaded every offline file during the app's first render (for an Uno app, ~60 font files and every icon and splash scale: about 5.5 MB of brotli).
Cache-first for package_<hash> files (except uno-config.js) and fingerprinted _framework files; other requests are network-first with a 4 s timeout. The whole body is read inside that window, so a reset falls back to the cache instead of truncating index.html.
Runtime caching: files the app fetches are cached as it uses them.
Install only caches what startup needs (the boot resources, package_* JS/CSS, uno-config.js, index.html). The rest of offline_files is cached in the background, three at a time, when the page posts an uno-precache message. This isn't done in activate: fetch events wait for activation to complete, so a reload would have waited for the whole precache.
Registration waits for the load event, 3 s, and an idle period.
WasmShellPWAPrecacheExclude (semicolon-separated globs, * and **) leaves files out of the background caching. They're still cached on use. The default excludes nothing, so offline behavior is unchanged.
Docs: "Offline support" section on the PWA page.
Validation
New Uno.Wasm.Tests.ServiceWorker (CI, linux). It loads the RayTracer to install the worker, checks the precache, then reloads with the server offline, then with every file's first request reset mid-body.
Before: offline reload OK, flaky reload fails.
After: both start, in ~1.1 s on the test server.
The RayTracer now sets WasmShellPWAPrecacheExclude=pwa-images/**. Of its 103 images, 0 are precached and every other published offline file is.
Measured with a prototype of this worker on a Uno 7.0 template app, through a test server simulating 4G (repeat visits, median, n=3): warm reload 2.41 → 1.55 s, offline 3.39 → 1.79 s, warm reload on a flaky network 2/3 → 3/3 started.
Found while testing, not changed here: offline_files lists WebWorker files with unexpanded #[.{fingerprint}] placeholders, and the worker's dotnet.js under a stale fingerprint. Those 404, so a WebWorker app can't start its worker offline. The test skips these entries.
A successful retry is returned without being added to the runtime cache. Consequently, an excluded asset whose first attempt exceeds the four-second window loads on the retry but is not available offline, contradicting the cached-on-use behavior. Track successful retry responses with the same event.waitUntil(putInCache(...)) path as the initial attempt.
The service worker was network-first for every request and only fell back
to its cache when fetch() rejected before the response headers arrived. A
connection dropping mid-body reached the app even with every file cached, so
a repeat visit on a flaky network could fail, and every file waited on the
network first. It also registered right after runMain, so its install-time
download of every offline file (fonts and icons included) competed with the
app's first render.
- package_<hash> files and fingerprinted _framework files are served from
the cache first; other requests are network-first with a 4 s timeout,
reading the whole body before answering so a reset falls back to the cache
- files the app fetches are cached as it uses them
- install caches only what boot needs; the remaining offline files are
cached in the background, a few at a time, on a message from the page
(not in 'activate', which holds back fetches until it completes)
- registration waits for the load event, a few seconds and an idle period
- WasmShellPWAPrecacheExclude leaves files out of the background caching
Measured on a simulated 4G link: repeat visits 36% faster (2.41 s ->
1.55 s), offline startup 3.4 s -> 1.8 s, and warm loads on a flaky
network no longer fail.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs
Every same-origin GET went through the 4s network-first path, so slow API
calls and streams were cut off, and their responses were cached and could
be replayed for a different query. Other requests now go to the browser
untouched, and no-store responses aren't cached.
Also reads retried responses fully, keeps null-body statuses bodiless, and
shares one background precache across tabs.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ADrzrqtw3RQdHan77rypBM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1092
What changed
The PWA service worker was network-first for every request, including the files that never change. It fell back to its cache only when
fetch()rejected before the response headers arrived, so a connection reset mid-body reached the app even with everything cached. It also registered right afterrunMain, and its install downloaded every offline file during the app's first render (for an Uno app, ~60 font files and every icon and splash scale: about 5.5 MB of brotli).package_<hash>files (exceptuno-config.js) and fingerprinted_frameworkfiles; other requests are network-first with a 4 s timeout. The whole body is read inside that window, so a reset falls back to the cache instead of truncatingindex.html.package_*JS/CSS,uno-config.js,index.html). The rest ofoffline_filesis cached in the background, three at a time, when the page posts anuno-precachemessage. This isn't done inactivate: fetch events wait for activation to complete, so a reload would have waited for the whole precache.loadevent, 3 s, and an idle period.WasmShellPWAPrecacheExclude(semicolon-separated globs,*and**) leaves files out of the background caching. They're still cached on use. The default excludes nothing, so offline behavior is unchanged.Validation
New
Uno.Wasm.Tests.ServiceWorker(CI, linux). It loads the RayTracer to install the worker, checks the precache, then reloads with the server offline, then with every file's first request reset mid-body.WasmShellPWAPrecacheExclude=pwa-images/**. Of its 103 images, 0 are precached and every other published offline file is.Measured with a prototype of this worker on a Uno 7.0 template app, through a test server simulating 4G (repeat visits, median, n=3): warm reload 2.41 → 1.55 s, offline 3.39 → 1.79 s, warm reload on a flaky network 2/3 → 3/3 started.
Found while testing, not changed here:
offline_fileslists WebWorker files with unexpanded#[.{fingerprint}]placeholders, and the worker'sdotnet.jsunder a stale fingerprint. Those 404, so a WebWorker app can't start its worker offline. The test skips these entries.🤖 Generated with Claude Code
https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs