# Web Workers

- Human documentation: [https://docs.univer.ai/guides/docs/getting-started/worker](https://docs.univer.ai/guides/docs/getting-started/worker)

- Agent Markdown: [https://docs.univer.ai/guides/docs/getting-started/worker.md](https://docs.univer.ai/guides/docs/getting-started/worker.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [docs/getting-started/worker.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/docs/getting-started/worker.mdx)

---

Docs can run document layout in a Web Worker[^web-worker] through `UniverDocsLayoutWorkerPlugin`. Register it after the Docs core plugin. `workerFactory` creates a fresh Worker for the layout service.

Start with [installation and basic usage](https://docs.univer.ai/guides/docs/getting-started/installation.md). The following snippets extend that setup. Register the plugins before creating or loading content; replace existing registrations rather than registering a plugin twice.

## Main thread

```typescript title="main.ts"
import { UniverDocsLayoutWorkerPlugin } from '@univerjs/docs'

univer.registerPlugin(UniverDocsLayoutWorkerPlugin, {
  workerFactory: () => new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' }),
})
```

## Worker entry

```typescript title="worker.ts"
import { startDocsLayoutWorker } from '@univerjs/docs'

startDocsLayoutWorker()
```

Use a module Worker and a separate entry file. Keep the Worker and main-thread package versions aligned. Rendering and user interaction stay on the main thread.

[^web-worker]: A Web Worker runs JavaScript outside the browser’s main thread and exchanges messages with it. It cannot access the page DOM directly; moving calculations into a Worker does not move the editor UI there.
