An on-device model can be ready without a network connection while the application around it still fails to reopen. The model works; the HTML, JavaScript, fonts, or saved input do not. From the user’s perspective, the feature is still offline and unavailable.
An offline promise therefore needs an interaction-level test. Close or reload the page without connectivity and check whether the person can recover their work, use the available features, and understand what is unavailable.
The companion implements a small React brief editor with local draft storage and a versioned application cache. Native AI remains optional and independently checked. The example does not queue bookings, synchronize accounts, or pretend that caching a shell turns a server-backed workflow into a complete offline application.
Track three independent kinds of readiness
The browser can have an application shell without a usable model, or a usable model without the application shell. The user’s draft is a third concern.
| Resource | Owner in this example | Readiness question |
|---|---|---|
| HTML, JavaScript, CSS | Application service worker | Can the editor reopen? |
| Synthetic brief | Application local storage | Can the person recover the text? |
| Built-in AI model | Browser | Can the selected API perform this task? |
Do not display a single “Offline ready” badge based only on successful service-worker registration. Registration does not establish that the worker controls this page, that all required assets were cached, or that the model can run.
Similarly, navigator.onLine is a connectivity hint. It cannot establish that a particular model endpoint or application API is reachable.
Cache the application shell deliberately
The build script collects the emitted HTML, JavaScript, and CSS and creates a cache name from their content hash. The generated service worker precaches that allowlist during installation.
self.addEventListener("install", event => { event.waitUntil( caches.open(CACHE).then(cache => cache.addAll(URLS)) ); }); CACHE and URLS are build-generated values, not placeholders in the delivered worker. If installation cannot obtain a required asset, it should fail rather than advertise a complete shell.
The example handles the root navigation with a network request and a cached fallback. Versioned assets use the active shell cache. Requests outside the same-origin allowlist are left alone.
This restriction matters. A broad “cache every GET” policy can capture personalized responses, unbounded resources, and data whose freshness rules differ from static application code. The lab has no authenticated API responses to cache.
Treat updates as an application decision
A new worker cleans up older caches bearing this application’s prefix when it activates. It does not delete unrelated caches from the origin.
The example also avoids forcing every new worker to activate immediately with skipWaiting(). Replacing the worker beneath an open editor can mix versions or interrupt work. A larger application should offer a controlled update after the person has saved or exported their draft.
Keep old assets available on the server for a suitable deployment window. A versioned cache helps a previously installed application, but it cannot rescue an asset that was never cached and has already been removed from the server.
Figure 1. Offline editing and offline inference require different resources.
Preserve input without overstating storage
The demonstration stores a small synthetic brief in localStorage. Its write path catches failures and tells the person to copy the text before closing the page.
try { localStorage.setItem("web-ai-lab-brief", text); } catch { setStorage("Local saving failed. Copy the brief before closing."); } This is intentionally modest. Storage is not a backup, a multi-device sync mechanism, or an appropriate default for every confidential document. Real products need a retention policy, deletion controls, and storage choices that fit their data and size requirements.
For a richer editor, IndexedDB may be more appropriate. Preserve the same user-facing rule: a failed write must not leave an unqualified “Saved” indicator on screen.
Keep model storage separate
The lab’s service worker does not attempt to cache Chrome’s built-in model internals. The application asks the API about the requested task and handles preparation or unavailability through the normal UI.
If you serve your own model through a library such as LiteRT.js, those model files and runtime assets become part of your application’s delivery design. Give them explicit versions, integrity records, download behavior, and cache rules. The companion excludes its benchmark’s model and Wasm files from the small editor-shell cache so that opening the editor does not silently download the benchmark workload.
Chrome’s model-caching guidance discusses models served by applications. Apply it to that delivery path rather than assuming every built-in model is a resource your service worker controls.
Test a cold visit and a returning visit separately
Build the production bundle with npm run build, then serve it with npm run preview. The development server deliberately does not register the production worker.
First load the application online, save a synthetic brief, and wait for the worker to become ready. Reload to establish control, then disable connectivity and reload again. Verify that the editor appears and that the saved text is correct.
Now repeat in a fresh profile that has never visited the application. An offline first visit has no installed shell to use. That should be reported as an unsupported scenario, not folded into a returning-user success rate.
The browser script passed this controlled-worker reload case in Headless Chrome 153. After saving a synthetic brief and establishing worker control, it disabled connectivity, reloaded, and recovered the exact saved text. The evidence file and screenshot record that result. This verifies the editor and draft; model inference still requires its own native preparation and offline run.
Finally test missing assets, storage failures, and a model that is unavailable even though the editor opens. A successful warm model call while the page remains open does not cover any of those scenarios.
The practical goal is continuity: people can recover their text and understand the remaining options. Which part of your application’s offline promise have you verified after a complete reload?


