DEDUPED Hot AI repos. Real use cases. What people build. Get the Monday 5

How to keep the model loaded across page visits with Web LLM

Run WebLLM in a Service Worker and pick a cache backend so the model is not reloaded on every visit and works better offline.

Short answer: Install with npm install @mlc-ai/web-llm; then in sw.ts instantiate ServiceWorkerMLCEngineHandler at the top level of the script; register the service worker in main.ts and create the engine with CreateServiceWorkerMLCEngine. All steps.

Who it is forA developer shipping a multi page app or PWA with local AI.

The problemReloading a multi gigabyte model on each page view is slow.

The outcomeA service worker engine shared across pages, with model files cached in the browser.

What you need first

  • 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

Steps

  1. Install with npm install @mlc-ai/web-llm
  2. In sw.ts instantiate ServiceWorkerMLCEngineHandler at the top level of the script
  3. Register the service worker in main.ts and create the engine with CreateServiceWorkerMLCEngine
  4. Optionally set AppConfig.cacheBackend to cache, indexeddb or opfs

Prompt for your agent

Using mlc-ai/web-llm, add a sw.ts with ServiceWorkerMLCEngineHandler, register it, create the engine with CreateServiceWorkerMLCEngine, and set cacheBackend to indexeddb.

Caveat. The README warns the browser can kill a service worker at any time, so add error handling.

Use this in your AI agent

Ask your agent

Using the Deduped MCP, get the setup steps for mlc-ai/web-llm and "Keep the model loaded across page visits"

Add Deduped to Claude Code once

claude mcp add --transport http deduped https://dedupedai.com/mcp

Cursor, ChatGPT, others

Share: X LinkedIn Hacker News Email Copy link

Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer