Chapter 10. Putting JavaScript to Work: Web Workers
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.
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 ...
Get Head First HTML5 Programming 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.