O'Reilly logo

jQuery Mobile Cookbook by Chetan K Jain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Web Workers for intensive tasks

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.

Getting ready

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.

How to do it...

The steps to be performed are as follows:

  1. Create main.html with a checkbox and a slider as its page content:
    <div data-role='content'> <div id='msgdiv'></div> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required