Lesson 33

Web Workers

JavaScript has always been a single threaded programming language. Essentially this means that the language is only capable of performing a single operation at a time, and therefore only capable of utilizing a single CPU on the underlying hardware.

This was not a problem when JavaScript was first created because the vast majority of devices that ran browsers supported only a single CPU. Over the last 10 years there has been a major change in hardware, however, and the vast majority of devices now support multiple CPUs. Even smart phones typically support up to four CPUs.

A programming language is considered multi-threaded if it is capable of specifying multiple sets of instructions that can be run in parallel. Each set of instructions is encapsulated inside a thread.

The key reason that multi-threaded programming languages are important is performance. If you envisage a device with four CPUs, it is capable of executing four sets of instructions in parallel. If a programming language is not multi-threaded, however, it is only capable of using 25 percent of ...

Get HTML5, JavaScript, and jQuery 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.