Chapter 27APIs: Web Workers

Every HTML5 app is written in JavaScript, but the single and the most crucial limitation of HTML5 apps is that the browsers’ JavaScript runtimes are single-threaded in nature. Some of you might say that you have run tasks asynchronously in the past using functions like setTimeout, setInterval, and our all-time favorite, XMLHttpRequest. But, in reality, those functions are just asynchronous, not concurrent. Actually, all JavaScript tasks run one after the other and are queued accordingly. Web Workers offer us a multi-threaded environment where multiple threads can execute in parallel, offering true concurrency.

In this chapter, we’ll first discuss the purpose and how to use Web Workers, before having a look at some ...

Get Jump Start HTML5 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.