When you run a script that does some complex or lengthy activity, the browser thread freezes and does not respond till the task is complete. This can be overcome by using a Web Worker—a background independent thread that is used to run JavaScript. The browser thread is not blocked, and thus can continue to respond to user actions. This recipe shows you how to use Web Workers.
Copy the full code of this recipe from the code/11/webworkers
folder. You can launch this code using the URL: http://localhost:8080/11/webworkers/main.html
.
The steps to be performed are as follows:
Create
main.html
with a checkbox and a slider as its page content:<div data-role='content'> <div id='msgdiv'></div> <div data-role='fieldcontain'> <input type="range" name="myslider" id="myslider" value='0' min="0" max="100" /> <label for="myslider">Slide me:</label> </div> <div data-role...