Overview
Web Workers allow for multi-threading in JavaScript. They enable you to run heavy computations in a background thread, preventing the main UI thread from becoming unresponsive or 'janky.'
Key Features
- Parallelism: Run code simultaneously with the main thread.
- No DOM Access: Workers cannot directly manipulate the DOM for safety reasons.
- Message Passing: Communication with the main thread is done via
postMessageandonmessageevents. - Improved Performance: Ideal for data processing, image manipulation, and complex calculations.
Comparison
Unlike Service Workers, Web Workers are tied to the specific page that created them and do not persist after the page is closed.