What do you understand by "Web Workers"?


Do you know JavaScript runs in a single-threaded environment? Yes, JavScript runs in single-threaded environment which means that we cannot run two scripts on webpage at a time.

Now assume any webpage which requires some calculation intense logic on webpage when any button is clicked. If the button is clicked the script starts executing and all other controls on webpage is blocked until the script completes execution. To overcome such situation HTML5 introduced Web Workers.

A worker is an object created using a constructor (e.g. Worker()) that runs a named JavaScript file - in the background, independently of other scripts, without affecting the performance of the page. Workers run in another global context that is different from the current window which makes possible to run scripts concurrently on webpage.

Share this thread


comments powered by Disqus


Social Media