← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Web Workers

JavaScript ES2015 Advanced
debt(d7/e5/b3/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints list chrome-devtools and lighthouse, which can flag long synchronous tasks and poor INP scores, but these tools catch symptoms (UI jank, slow INP) rather than directly flagging 'you should use a Web Worker here.' A developer must interpret profiler output and recognize that the bottleneck is CPU-bound and off-threadable — this requires careful analysis rather than an automated fix suggestion. Slightly better than d9 because Lighthouse/DevTools do surface the evidence.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix says 'offload CPU-intensive tasks to Web Workers,' but this is not a one-line patch. It requires creating a worker file, restructuring the computation to be message-based (postMessage back and forth), handling transferable objects, managing worker lifecycle, and updating the calling code — spanning at least two files and a meaningful refactor. Not quite a cross-cutting architectural rework (e7), but clearly more than a small parameterised fix.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). Web Workers apply only to web contexts and only to specific CPU-intensive tasks within a component. Once implemented correctly, the rest of the codebase is largely unaffected. The worker pattern is self-contained — a worker file plus a manager — so future maintainers pay a modest overhead understanding the postMessage boundary but it doesn't shape the entire codebase.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field explicitly states that developers believe Web Workers speed up all JavaScript, when they only help CPU-bound tasks — I/O-bound async operations gain nothing. Additionally, common_mistakes highlight DOM access attempts (workers have no DOM) and cloning vs. transferring large objects. These are documented, well-known gotchas that most developers encounter and learn, placing this squarely at t5 rather than a more severe trap level.

About DEBT scoring →

Also Known As

Web Worker background thread postMessage OffscreenCanvas

TL;DR

Background threads in the browser that run JavaScript without blocking the main thread — essential for CPU-intensive tasks that would otherwise freeze the UI.

Explanation

Web Workers run in a separate thread with no access to the DOM. Communication is via postMessage/onmessage with structured clone serialisation. Use for: heavy computation (image processing, encryption, data parsing), running WASM modules, and large data transformations. Service Workers are a specialised type for network interception. SharedArrayBuffer enables shared memory between workers (requires COOP/COEP headers). Workers solve the 'why does my page freeze?' problem for CPU-intensive code.

Common Misconception

Web Workers speed up all JavaScript — they only help CPU-bound tasks; I/O-bound tasks (fetch, IndexedDB) are already async and don't need workers.

Why It Matters

CPU-intensive JavaScript (parsing large CSV, image manipulation, encryption) freezes the browser UI — Web Workers move that work off the main thread so the page remains responsive.

Common Mistakes

  • Trying to access the DOM from a worker — workers have no DOM access; pass data back via postMessage.
  • Transferring large objects by clone instead of transfer — use Transferable objects (ArrayBuffer) to move memory without copying.
  • Creating workers inside loops — each worker has overhead; create a pool and reuse workers.
  • Not terminating workers when done — idle workers consume memory and CPU resources.

Code Examples

✗ Vulnerable
// CPU-intensive task on main thread — freezes UI:
btn.addEventListener('click', () => {
    const result = processLargeDataset(millionRows); // Blocks UI for seconds
    displayResult(result);
});
✓ Fixed
// Offload to Web Worker — UI stays responsive:
// worker.js:
self.onmessage = ({ data }) => {
    const result = processLargeDataset(data.rows);
    self.postMessage({ result });
};

// main.js:
const worker = new Worker('worker.js');
btn.addEventListener('click', () => {
    worker.postMessage({ rows: millionRows }); // Non-blocking
});
worker.onmessage = ({ data }) => displayResult(data.result);

Added 15 Mar 2026
Edited 22 Mar 2026
Views 105
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings T 1 ping F 1 ping S 1 ping S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 1 ping M 1 ping T 0 pings W 1 ping T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Scrapy 14 Google 9 Amazonbot 8 Perplexity 7 ChatGPT 7 PetalBot 7 Ahrefs 6 SEMrush 5 Unknown AI 3 Brave Search 3 Majestic 2 Applebot 2 Qwen 1 Meta AI 1 Twitter/X 1 Bing 1
crawler 71 crawler_json 5 pre-tracking 1
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
JavaScript javascript The programming language of the browser — it reads and modifies the page (the DOM), reacts to user events, and fetches data without reloading.

JavaScript is the only language browsers execute, so every interactive behaviour on the web goes through it. Its two defining traits — single-threaded event loop and loose typing (== coercion) — explain the majority of both its bugs and its design patterns.

💡 Default to const, use === always, and reach for let only when a value genuinely reassigns.

Ask Codex about JavaScript →
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Offload CPU-intensive tasks (image processing, data parsing, encryption) to Web Workers — they run on separate threads without blocking the main thread's UI
📦 Applies To
javascript ES2015 web
🔗 Prerequisites
🔍 Detection Hints
Long synchronous operations on main thread causing INP >200ms; JSON.parse of large response blocking UI; heavy computation in click handler
Auto-detectable: ✓ Yes chrome-devtools lighthouse
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File Tests: Update


✓ schema.org compliant