{
 "schema_version": 1,
 "generated": "2026-11-09",
 "id": "mlc-ai-web-llm--stream-replies-from-a-web-worker-with-web-llm",
 "repo": "mlc-ai/web-llm",
 "repo_url": "https://github.com/mlc-ai/web-llm",
 "repo_slug": "mlc-ai-web-llm",
 "title": "Stream replies without freezing the page",
 "page_title": "How to stream replies without freezing the page with Web LLM",
 "summary": "Move inference into a Web Worker with WebWorkerMLCEngineHandler and stream tokens back with stream true.",
 "who": "A front end developer whose UI stutters while the model runs.",
 "problem": "Running a model on the main thread blocks the interface.",
 "outcome": "A responsive page that shows tokens as they arrive.",
 "steps": [
  "Install with `npm install @mlc-ai/web-llm`",
  "In worker.ts create a WebWorkerMLCEngineHandler and forward self.onmessage to it",
  "In main.ts create the engine with CreateWebWorkerMLCEngine and a new Worker for worker.ts",
  "Call chat.completions.create with stream: true and stream_options include_usage, appending each chunk's delta content"
 ],
 "agent_prompt": "With mlc-ai/web-llm, refactor <my chat page> to use CreateWebWorkerMLCEngine with a worker.ts handler and stream tokens into the message box.",
 "agents": [
  "claude-code",
  "codex",
  "cursor",
  "gemini-cli"
 ],
 "difficulty": "Intermediate",
 "time": "1 hour",
 "basis": "readme",
 "caveat": "Only the last streamed chunk carries usage numbers.",
 "category": "Software and DevOps",
 "tags": [
  "Software and DevOps"
 ],
 "lang": "",
 "requirements": [
  "A browser with WebGPU support on a device with a capable GPU",
  "Node with npm, yarn or pnpm: `npm install @mlc-ai/web-llm`, or import from the jsdelivr CDN",
  "Bandwidth and storage for the first model download, which the README warns can take a significant amount of time"
 ],
 "risk": "none",
 "seen_in_the_wild": false,
 "mentioned_publicly": false,
 "risks": [],
 "best": false,
 "score": 0.9,
 "evidence": [],
 "url": "https://dedupedai.com/use-cases/mlc-ai-web-llm/stream-replies-from-a-web-worker-with-web-llm/",
 "md": "https://dedupedai.com/use-cases/mlc-ai-web-llm/stream-replies-from-a-web-worker-with-web-llm/index.md",
 "disclaimer": "Deduped lists open-source repositories that belong to other people. We do not own, maintain, audit, or vouch for any of them, and a repo appearing here is not an endorsement or a safety check. The use cases, steps, and prompts are written by AI and may be incomplete, outdated, or just wrong. Where a use case is marked \"Seen in the wild\", we link to public posts where someone described something similar, but we have not verified those posts and the use case itself is still our AI's own write-up. Use all of this at your own risk. Only run code, commands, or agents on systems and accounts you are authorized to use, and read the code and every command before you run it, especially anything that touches credentials, files, or the network. Nothing here is professional, security, legal, or financial advice. All trademarks and project names belong to their respective owners, and their use here does not imply affiliation. Content is provided as is, without warranties of any kind. Found a mistake, a safety problem, or something you want removed? Email hello@dedupedai.com and we will look at it promptly.",
 "api": "https://dedupedai.com/api/v1/usecases/mlc-ai-web-llm--stream-replies-from-a-web-worker-with-web-llm.json",
 "api_version": "v1"
}
