Home/Blogs/Web Workers & Multithreading
Performance Engineering

Web Workers: True Multithreading and Offscreen Processing in JavaScript

By Crate Editorial Team•Published Oct 24, 2026•10 min read

JavaScript is famously single-threaded. When your web application runs a complex mathematical operation, compresses a 50-megapixel photo, or extracts an audio waveform, that computation runs on the exact same thread responsible for rendering HTML, painting CSS animations, and responding to user clicks. The result is the dreaded browser freeze: stuttering scrolling, unresponsive buttons, and failed interactions.

To build desktop-class web applications like Crate, offloading heavy computations to Web Workers is mandatory. Here is how modern web developers harness hardware multi-core CPUs in the browser.

Advertisement
Google AdSense Partner SlotActive upon AdSense domain verification

The Main Thread vs. Background Workers

A standard browser tab allocates one primary thread for the DOM and user interface. If a task occupies this thread for more than 16 milliseconds (on 60Hz displays) or 8 milliseconds (on 120Hz displays), a frame is dropped (known as jank).

A Dedicated Web Worker spawns a completely separate OS-level thread. While it cannot touch the DOM (`document` or `window` are undefined), it possesses full access to timers, `fetch`, WebSockets, IndexedDB, and WebAssembly execution runtimes.

The Zero-Copy Breakthrough: Transferable Objects

Historically, passing data between the main thread and a Web Worker used the structured clone algorithm. If you passed a 200MB uncompressed raw video buffer to a worker, the browser duplicated that 200MB in memory, causing a momentary micro-stutter.

Transferable Objects eliminate cloning completely. By transferring ownership of an `ArrayBuffer`, the memory is moved instantaneously (in zero milliseconds) from the main thread to the worker context without memory duplication:

// Main Thread: Zero-Copy Transfer
const worker = new Worker('/workers/image-filter.js'); // Create large 100MB typed array const rawPixelBuffer = new Uint8Array(100 * 1024 * 1024).buffer; // Pass the buffer as the 2nd argument (Transferable list) worker.postMessage({ buffer: rawPixelBuffer }, [rawPixelBuffer]); // Notice: rawPixelBuffer.byteLength is now 0 on the main thread! console.log(rawPixelBuffer.byteLength); // 0 (Ownership transferred)

OffscreenCanvas: Hardware-Accelerated Worker Rendering

Traditionally, graphics rendering had to occur on the main thread because canvas elements live in the DOM. With `OffscreenCanvas`, you can transfer control of an HTML <canvas> directly into a Web Worker:

// Main Thread
const canvas = document.querySelector('canvas'); const offscreen = canvas.transferControlToOffscreen(); worker.postMessage({ canvas: offscreen }, [offscreen]);

In game engines like TypeCrate or real-time video filters, the Web Worker renders 2D/WebGL graphics continuously without ever blocking typing inputs, keyboard events, or modal dialogues on the main page.

SharedArrayBuffer & Atomics: Shared Memory Multiprocessing

For ultra-high performance applications (such as multi-threaded FFmpeg WASM builds), multiple workers can read and write to the exact same memory address concurrently using `SharedArrayBuffer`. To prevent race conditions, the `Atomics` API provides atomic read, write, and wait/notify primitives matching native C++ threading models.

Security Note (COOP / COEP):Because of historical side-channel timing attacks (Spectre), browsers require specific HTTP headers (`Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`) to unlock `SharedArrayBuffer` support in production.

Summary: When to Spawn a Worker

  • Always use Workers: Video/audio transcoding, image resizing/quantization, cryptographic hashing, heavy text parsing, AI model inference.
  • Keep on Main Thread: Quick DOM updates, standard form validation, micro-animations handled via CSS transforms.
Advertisement
Google AdSense Partner SlotActive upon AdSense domain verification
Crate Creative Suite

More Free Creator Tools

100% private, client-side tools designed for video editors and creators.

Popular

Crate Captions

Auto-generate gapless 1w–5w word subtitles with smart emojis for CapCut, Premiere, & Shorts.

Video & SubtitlesLaunch →

Video Compressor

Compress MP4 and MOV videos up to 85% using in-browser WebAssembly with zero quality loss.

Video & SubtitlesLaunch →

Extract Audio

Rip clean uncompressed WAV audio from any MP4, MOV, or WebM video locally in seconds.

Audio UtilitiesLaunch →

Compress Image

Batch optimize JPEG, PNG, and WebP images client-side with interactive before/after inspection.

Image ToolsLaunch →

Remove Background

Instant neural foreground isolation. Create transparent PNG cutouts without server uploads.

Image ToolsLaunch →

Convert Image

Bulk convert WebP to PNG/JPG, PNG to WebP/JPG, or JPG to WebP with one-click ZIP download.

Image ToolsLaunch →

Resize Image

Batch resize photos by pixel dimensions or percentages with aspect ratio lock and ZIP export.

Image ToolsLaunch →

Crop Image

Crop images visually with 16:9, 1:1, 9:16, and 4:5 social presets with zero quality loss.

Image ToolsLaunch →

Rotate Image

Batch rotate images 90°, 180°, or 270° and mirror flip horizontally or vertically.

Image ToolsLaunch →

Watermark Image

Batch stamp copyright text or branding across photos with 9-point grid and diagonal repeat.

Image ToolsLaunch →

Blur & Censor Image

Blur faces, pixelate sensitive personal info, or blackout credit card numbers 100% in-browser.

Image ToolsLaunch →

Meme Generator

Create viral memes with classic Impact captions, custom image upload, and zero watermarks.

Image ToolsLaunch →

Crate Drop

Stream gigabyte files directly between two devices over encrypted peer-to-peer Wi-Fi channels.

File TransferLaunch →
Popular

Font Style Changer

Transform text into 50+ aesthetic Unicode fonts for Instagram bios, TikTok captions, & Discord.

Text & TypographyLaunch →