Cover by Eric Freeman, Elisabeth Robson

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

O'Reilly logo

Chapter 10. Putting JavaScript to Work: Web Workers

image with no caption

Slow script—do you want to continue running it?

If you’ve spent enough time with JavaScript or browsing the Web you’ve probably seen the “slow script” message. And, with all those multicore processors sitting in your new machine how could a script be running too slow? It’s because JavaScript can only do one thing at a time. But, with HTML5 and Web Workers, all that changes. You’ve now got the ability to spawn your own JavaScript workers to get more work done. Whether you’re just trying to design a more responsive app, or you just want to max out your machine’s CPU, Web Workers are here to help. Put your JavaScript manager’s hat on, let’s get some workers cracking!

The Dreaded Slow Script

One of the great things about JavaScript is it does only one thing at a time. It’s what we like to call “single-threaded.” Why’s that great? Because it makes programming straightforward. When you have lots of threads of execution happening at the same time, writing a program that works correctly can become quite a challenge.

image with no caption

The downside of being single-threaded is that if you give a JavaScript program too much to do, it can get overwhelmed, and we end up with “slow script” dialogs. The other ramification of having only one thread is if you have JavaScript ...

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