📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What are Web Workers, and when would you move JavaScript work off the main thread?

Beginner Theory Beginner

🎯 Key points

  • Separate thread, own event loop
  • No DOM access
  • postMessage with structured clone or transferables (ArrayBuffer) to avoid copies
  • Good for CPU-bound parsing, image work, crypto in a SPA or Blazor WebAssembly app
  • Costs: setup, message-passing complexity, copy overhead
  • Often better to do heavy work on the server or paginate instead

⏱ 30-second answer

A Web Worker runs a script on a separate thread with its own event loop. It can't touch the DOM; it talks to the page with postMessage (structured clone or transferable objects). Use it for CPU-heavy work such as parsing a large file, image processing or crypto, so the main thread stays responsive. The cost is copying data across and more complex code, so first check whether the work could be done on the server or paginated.

🔍 What the interviewer is checking

Checks they know the browser's only real parallelism model and its limits

↩ Usually asked after

More in Web Basics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me