Web Worker

Noun · Development

Definitions

  1. Web Worker is a JavaScript API that enables running scripts in background threads separate from the main execution thread of a web page, allowing computationally intensive tasks to be performed without blocking the user interface. Since JavaScript in the browser is single-threaded (sharing the main thread with DOM rendering and event handling), long-running calculations can freeze the UI, making the page unresponsive. Web Workers solve this by executing code in an isolated thread that cannot access the DOM but can communicate with the main thread through a message-passing interface using postMessage() and onmessage event handlers. This design prevents race conditions by ensuring there is no shared mutable state between threads. Types of workers include dedicated workers (owned by a single page), shared workers (accessible from multiple pages of the same origin), and service workers (which act as programmable network proxies for offline support and push notifications). Web Workers are used for image processing, data parsing, encryption, complex calculations, and any task that would otherwise block rendering.

    In plain English: A way to run heavy JavaScript calculations in the background so the website stays responsive.

    Example: "Move the CSV parsing into a Web Worker — processing 100MB on the main thread freezes the UI for 10 seconds."

Related Terms