O'Reilly logo

Mastering JavaScript High Performance by Chad R. Adams

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

Web workers

Web workers give JavaScript developers like us a way to build multi-threaded JavaScript applications; this works in newer browsers as we have an object called a worker. A worker object is simply an external JavaScript file that we pass logic to.

Now, this may seem a little odd. Haven't we worked with external JavaScript files, since the beginning of JavaScript? Fair enough, but web workers are a bit new in terms of how a browser handles the execution of files in the DOM. Let's take a look at the following sample diagram on how a browser reads a file:

Web workers

So here we have a single-threaded JavaScript application, a DOMContentLoaded event, and ...

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