Direct Answer
WebLLM is a JavaScript runtime for executing selected language-model artifacts inside a compatible browser with WebGPU. A production WebLLM feature is not just a call to CreateMLCEngine. It is a release system for model artifacts, browser capabilities, storage, workers, privacy, fallbacks, quality, and recovery.
Use browser inference when the measured workload fits supported devices and local execution creates concrete value. Keep a remote or non-AI path when coverage, startup time, quality, energy use, accessibility, or reliability does not meet the product contract.
Key Takeaways
- Pin the WebLLM package, model ID, model files, tokenizer, model library, chat template, and integrity metadata as one release.
- Feature-detect WebGPU and request a real adapter/device; a user-agent string is not sufficient.
- Treat OpenAI-style method names as an adapter surface, not proof of request and response equivalence.
- Select Cache API, IndexedDB, OPFS, or experimental cross-origin caching through measured lifecycle requirements.
- Prefer a dedicated Web Worker for UI responsiveness; use a Service Worker only with restart and reconnect handling.
- Enable artifact integrity verification and fail closed for production releases.
- Measure cold start, warm start, quality, memory pressure, device loss, energy, and fallback behavior by device class.
- Local inference narrows one data path. It does not automatically establish privacy, compliance, or zero cost.
The Browser Inference Stack
WebLLM combines several separately versioned layers:
A package upgrade can change APIs. A model artifact can change tokenization or output behavior. A browser or driver update can change feature support and memory behavior. Treat the combination as the unit to test and release.
Build a Versioned Artifact Contract
Do not configure production from an unpinned “latest models” menu. Keep a manifest for every accepted browser model:
{
"release": "browser-assistant-17",
"webllm_package": "pinned npm version",
"model_id": "verified model ID",
"model_source_revision": "immutable revision",
"model_lib": "immutable URL or bundled path",
"tokenizer_revision": "immutable revision",
"chat_template_revision": "sha256:...",
"integrity": {
"config": "sha256-...",
"model_lib": "sha256-...",
"tokenizer": {
"tokenizer.json": "sha256-..."
},
"on_failure": "error"
},
"license_review": "approved record ID",
"evaluation_run": "browser-eval-42"
}
The official WebLLM configuration supports optional Subresource Integrity metadata for configuration, WebAssembly, and tokenizer files. When the field is absent, the runtime behaves as before and does not verify those artifacts. For a controlled release, omission must be an explicit risk decision rather than an unnoticed default.
Integrity proves that bytes match the declared digest. It does not prove that the artifact is safe, licensed, accurate, or compatible with the current runtime.
Capability Detection Is a Runtime Test
navigator.gpu is only the first signal. A usable path should also handle:
- no WebGPU object;
- no adapter;
- required feature or limit unavailable;
- device creation failure;
- model download or integrity failure;
- storage quota or cache failure;
- out-of-memory during load or generation;
- device loss after a successful start;
- tab suspension or worker termination.
Do not convert a failed local path into a silent cloud upload. Ask for consent when the fallback changes where data is processed, and preserve the user's ability to continue without AI when possible.
OpenAI-Style Does Not Mean Drop-In Equivalent
WebLLM exposes an engine.chat.completions.create(...) interface and documents streaming, JSON mode, seeding, and other familiar fields. That is valuable for adapters, but conformance is bounded:
- the model is selected when the engine is created or reloaded, so a request-level
modelfield is ignored; - function calling is documented as work in progress;
- model-specific chat templates affect behavior;
- supported structured-output constraints may differ from hosted APIs;
- streaming chunks, usage accounting, cancellation, and errors require direct tests;
- a browser runtime has storage, worker, device, and lifecycle failures that a remote API client may not expose.
Build an internal request and result contract, then write separate adapters for WebLLM and remote providers. Passing the same TypeScript shape is not proof that the two paths produce equivalent semantics.
Choose a Cache Backend Deliberately
Current WebLLM configuration documents four cache backends:
| Backend | Useful property | Boundary to test |
|---|---|---|
Cache API (cache) |
current default and broad web integration | quota, eviction, origin lifecycle, update invalidation |
IndexedDB (indexeddb) |
structured origin storage | transaction failure, quota, browser cleanup, migration |
OPFS (opfs) |
origin-private file storage and optional sync handles | feature support, access mode, worker compatibility, deletion |
Cross-origin (cross-origin) |
experimental shared artifact path through a browser extension | extension dependency, fallback, trust, no programmatic tensor-cache deletion |
The official documentation says an unsupported OPFS configuration fails with an availability error. It also says the experimental cross-origin backend falls back when its extension is unavailable and does not currently support programmatic tensor-cache deletion.
Those are product requirements, not implementation trivia. If a user requests deletion or the model is revoked, the application must know which backend owns the bytes and whether it can remove them.
Web Worker and Service Worker Are Different Lifecycles
A dedicated Web Worker moves model loading and inference away from the main UI thread for the active page. This reduces rendering contention but does not make memory unlimited or eliminate message-copy cost.
A Service Worker can help reuse an engine beyond one page instance. The browser owns its lifetime and may stop it without notifying the application. WebLLM uses heartbeat behavior, but the product still needs:
- reconnect and engine-readiness states;
- idempotent request identity;
- recovery after worker restart;
- a policy for in-flight output;
- cache and model-reload UX;
- bounded retries and cancellation.
Do not promise “load once and stay resident forever.” Browser process management, storage pressure, OS policy, and user actions can invalidate that assumption.
A Go Release Gate for Browser Profiles
The browser runtime is JavaScript, but release acceptance can remain language-independent. This Go program rejects a measured device profile that lacks required evidence:
package main
import (
"errors"
"fmt"
)
type BrowserProfile struct {
Name string
WebGPU bool
ArtifactIntegrity bool
ColdStartSeconds float64
WarmStartSeconds float64
PeakMemoryMiB int
TaskPassRate float64
FallbackVerified bool
DeletionVerified bool
DeviceLossRecovered bool
}
func qualify(profile BrowserProfile) error {
switch {
case !profile.WebGPU:
return errors.New("WebGPU unavailable")
case !profile.ArtifactIntegrity:
return errors.New("artifact integrity not enforced")
case profile.ColdStartSeconds > 20:
return errors.New("cold start exceeds product budget")
case profile.WarmStartSeconds > 4:
return errors.New("warm start exceeds product budget")
case profile.PeakMemoryMiB > 4096:
return errors.New("peak memory exceeds device-class budget")
case profile.TaskPassRate < 0.92:
return errors.New("task quality below acceptance threshold")
case !profile.FallbackVerified:
return errors.New("fallback path not verified")
case !profile.DeletionVerified:
return errors.New("artifact deletion not verified")
case !profile.DeviceLossRecovered:
return errors.New("device-loss recovery not verified")
default:
return nil
}
}
func main() {
profile := BrowserProfile{
Name: "desktop-canary",
WebGPU: true,
ArtifactIntegrity: true,
ColdStartSeconds: 11.8,
WarmStartSeconds: 1.7,
PeakMemoryMiB: 2380,
TaskPassRate: 0.95,
FallbackVerified: true,
DeletionVerified: true,
DeviceLossRecovered: true,
}
if err := qualify(profile); err != nil {
panic(err)
}
fmt.Printf("%s accepted\n", profile.Name)
}
Expected output:
desktop-canary accepted
The thresholds are example product policy, not universal WebLLM requirements. Define them from the target task and device population.
Privacy Requires a Complete Data-Flow Review
Local model execution can prevent prompt text from being sent to a model API. The broader application may still transmit:
- model and tokenizer requests to a CDN;
- crash reports and performance telemetry;
- analytics events containing user or device identifiers;
- remote tool calls or retrieval queries;
- cloud fallback prompts;
- synchronization or account data;
- content exposed by extensions or injected scripts.
WebGPU also has explicit security and privacy considerations, including device-specific limits, performance characteristics, driver behavior, resource exhaustion, and fingerprinting surfaces. A browser sandbox is valuable, but it is not a promise that a page cannot leak data through allowed network or application code.
Create separate controls for local inference, network egress, telemetry, storage, deletion, and remote fallback. Test them with the browser developer tools and a controlled proxy.
Evaluate the Workload, Not the Demo
Measure at least:
| Dimension | Evidence |
|---|---|
| Coverage | successful adapter and device creation by browser, OS, and hardware class |
| Cold start | bytes downloaded, compile/load time, cancellation, retry |
| Warm start | cache hit, validation, reload, eviction recovery |
| Quality | fixed task set, exact artifact identity, accepted-output rate |
| Responsiveness | main-thread blocking, stream cadence, input latency |
| Memory | load peak, generation peak, device-loss frequency |
| Energy | battery drain, thermal throttling, sustained-task behavior |
| Privacy | observed network requests, telemetry, fallback, deletion |
| Reliability | worker restart, offline start, partial artifact, upgrade rollback |
Report distributions and device slices. A tokens-per-second number from one desktop does not establish mobile support, and a successful single prompt does not prove that a model fits the product.
Release and Rollback
A safe rollout uses immutable identities and small cohorts:
- publish the manifest and artifact digests;
- test integrity and cache migration on a canary origin;
- run quality and abuse fixtures on supported device classes;
- verify offline and remote-fallback UX;
- release to a bounded cohort;
- monitor load failures, device loss, task acceptance, energy, and fallback;
- keep the previous manifest available for rollback;
- revoke and delete defective artifacts where the backend permits it.
Do not let a mutable model URL silently change the binary behind a cached product.
Common Failure Modes
| Failure | Better design |
|---|---|
| hard-coded “minimum VRAM” | measured device profiles and load failure handling |
| user-agent compatibility table | feature, adapter, device, and workload tests |
| “OpenAI compatible” base-URL swap | adapter conformance suite |
| Cache API assumed permanent | eviction, quota, migration, and deletion tests |
| Service Worker assumed immortal | reconnect and reload state machine |
| local inference labeled private | end-to-end network and storage review |
| no artifact digest | optional SRI configured to fail closed |
| silent cloud fallback | explicit consent and equivalent policy controls |
Frequently Asked Questions
Which browsers support WebLLM?
Support depends on the current browser, OS, GPU, driver, required features, and runtime. Check compatibility data, then request a real adapter/device and run a small canary workload.
Is a smaller quantized model always faster?
No. Weight size affects download and memory, but kernel support, dequantization, context length, batch policy, browser implementation, and device can reverse a simple bit-width comparison. Benchmark the accepted task.
Can WebLLM work fully offline?
It can after every required artifact and application asset is available in a supported cache, but browser eviction, service-worker lifecycle, updates, licenses, and remote tools can break that path. Test offline startup after a browser restart.
How should a model update be deployed?
Publish a new immutable manifest, verify integrity, run the same device and task suite, migrate or isolate caches, canary the release, and keep the previous manifest for rollback.
When should a product avoid browser LLM inference?
Avoid it when target devices lack coverage, cold-start cost is unacceptable, the task needs a larger or higher-quality model, local energy use is unreasonable, or the product cannot provide a clear fallback and support policy.
Conclusion
WebLLM makes browser-native language-model inference possible, but production readiness comes from the surrounding contract. Pin the full artifact identity, verify bytes, choose storage with deletion and migration in mind, model worker termination, test API adapters, observe the complete data flow, and qualify real device classes. Browser inference is one deployment path, not an automatic promise of privacy, performance, or offline reliability. Compare it with local server deployment and evaluate model quantization as a separate artifact decision.