Web Worker
A browser API that runs JavaScript on a background thread, so heavy computation doesn't block the main thread and freeze the UI.
· Reviewed by senior engineers
A Web Worker is a browser API that runs a script on a background thread, separate from the main UI thread. The two communicate via message passing. Workers cannot touch the DOM directly, but they can do heavy computation, parsing, encryption, image manipulation or background sync without freezing the page.
The use case is anything CPU-bound on a real device. Parsing a large CSV, running client-side analytics, image processing in a photo editor, search indexing, ML inference with TensorFlow.js — all of these grind the main thread to a halt and tank INP if done synchronously. Move them to a worker and the UI stays at sixty frames per second.
The rough edges are ergonomics and serialisation. Communication is async-only, and structured cloning of large objects has its own cost. Libraries like Comlink hide most of the boilerplate. Service Workers are a sibling API focused on network interception, not computation — different problem, different tool.
We pull workers out when profiling shows main-thread work is the bottleneck for interaction latency. They aren't a default but they are a high-leverage option for compute-heavy product surfaces.
