Back EndBlogs

Web Workers

JavaScript includes a number of features that enable you to program asynchronously, including call backs, promises, and asynch/await. But all of these asynch processes still rely on the main browser thread to execute their code after any delay has taken place, such as a set time-out or a response to an ajax request.

The modern browsers support some newer additions to JavaScript that make use of additional threads. One of these newer additions is Web Workers.

Web Workers

A Web Worker enables you to specify code that will be executed in its own thread on the processor separate from the browser thread. This enables you to make your code asynchronous and also allows your app to do multiple things at once by leveraging one or more additional processor threads.
With a Web Worker, your app sends a message to the code running in the additional thread. This code does the requested work on its thread then responds with its own message, which often contains data that’s then used in your app. Web Workers are most useful in an app that needs to do complex processing, such as involved mathematical operations. Sending a task like this to a Web Worker frees up the browser thread so your user interface remains responsive.


Thanks for reading

Resources :

  • Lynda.com
  • Google.com
  • Wikipedia

Comment here