Web Workers
JavaScript is traditionally a single-threaded language as we learned from asynchronous programming. That is, when one callback function is running, others have to wait until its finish. Web Workers introduce a means for JavaScript to run content in the background. Once being created, Web Workers can communicate with other JavaScript code via postMessage
and vice versa.
Note that Web Workers are designed to perform computationally-heavy tasks, such as matrix calculations. They do not have access to the DOM; instead, I/O operations, e.g., XMLHttpRequestt
and fetch
, are unrestricted.
More details can be found at MDN Web Docs. Now let us explore Web Workers.