What is HTML5 web workers

In this article I have described the web workers in HTML5
  • 2227


A web workers is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. All JavaScript code would run in the same thread as the UI of that browser window. The result was that all long-running scripts would cause the browser window to freeze until processing finished. A worker is a thread, it allows you toperform tasks in a background process in parallel of the main browser process. If the script took long enough, the browserwould prompt the user to see if he/she wanted to stop the unresponsive script.
Browser Support

Web Worker(s) are supported by the following browsers.

Browser WebWorker supporting
Chrome v3 Yes
Fire fox v3.5 Yes
IE v9 Yes
Opera 10.6 Yes
Safari 4 Yes

Note: Browser Earlier versions, do not support web workers.

Example of web workers for iterations

<title>Bigger for loop</title>
function Loop()
                       for (var i = 0; i <= 10000000000; i += 1)
             var j = i;
                 alert("Completed " + j + "iterations" );
 function Hello()
                    alert("Hi Hello jee...." );
<input type="button" onclick="Loop();" value="B_Loop" />
<input type="button" onclick="Hello();" value="Hello" />

My 1st Web Worker

HTML5 Web Workers will be executed on separated threads, you need to host their code into separated files from the main page. Web Workers and the main page are communicating via messages. Those messages can be rmed with normal strings. To illustrate simple message posting, we're going to start by reviewing a very basic sample. It will post a string to a worker that will simply concatenate it with something else. To do that, add the following code into the "Bigger for loop/Hi Hello jee is msg" file.

Further Readings

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.