Web workers
Web workers bring the ability to execute code outside the main UI thread. This thread-like behavior allows us to perform long lasting tasks without blocking the user interface. When a JavaScript task takes too long to complete, the browser displays an alert to the user, letting the user know that the page is not responsive. Using web workers, we can solve this problem.
There are a few restrictions with web workers that we need to keep in mind. First, workers run outside the DOM, so any functionality related to that is not available inside worker threads. Also, there is no concept of shared memory with workers—any data that is passed to and from a worker is copied into its own memory space. Finally, any objects passed to and from a worker can contain any data types, except for functions. If you attempt to pass a function to or from a worker (or an object holding a reference to a function), the browser will throw a DataCloneError (DOM Exception 25).
On the other hand, workers are...