Web Worker
A script that runs on its own background thread, separate from the page's main thread, so heavy computation does not freeze the page.
In more detail
Workers have no access to the DOM, window or document; they talk to the page by passing messages with postMessage and the message event. Use them for parsing, image processing or number crunching that would otherwise cause long tasks.
Related terms
- postMessage() — The method used to send data between a page and a worker, or between windows, delivered as a message event on the other side.
- structured clone algorithm — The standard JavaScript algorithm for deep-copying values between threads and into storage, which handles Maps, Sets, Dates, typed arrays and circular references.
- transferable object — An object, such as an ArrayBuffer, ImageBitmap or MessagePort, whose memory can be moved to another thread instead of copied.
- main thread — The first thread a program starts with; in a browser page it also runs JavaScript and handles input, layout and painting.
- thread — A path of execution inside a process that the operating system schedules on a processor; one process can have many.
- Partytown — An open-source library that moves third-party scripts into a web worker so they do not slow down the main thread.
Taught in
- How Browsers Work: Navigation, DNS, TCP, TLS And Request Timing — Frontend Architecture & Web Platform
- requestAnimationFrame vs requestIdleCallback: High-FPS Work — Frontend Architecture & Web Platform
- Web Workers: Off-Thread Computation And Structured Clone — Frontend Architecture & Web Platform
- Script Optimization: next/script & Lazy Third Parties — Next.js 15 & Modern App Router Architecture