DMXzone Summer Sale: Save up to 51% with code DMXSUMMER26. Ends in

Getting Started With Web Workers

Overcome the limitation of the JavaScript single threade with HTML5

One of the many design goals of the JavaScript language was to keep it single-threaded and, by extension, simple. Though Agraj Mangal must admits that, given the idiosyncrasies of the language constructs, it is anything but simple! But what he means by being “single-threaded” is that there is only one thread of control in JavaScript; yes, sadly, your JavaScript engine can do only one thing at a time. Now, doesn’t that sound too restrictive to make use of multi-core processors lying idle on your machine? HTML5 promises to change all of that.

 

One school of thought considers JavaScript’s single-threaded nature as a simplification, but the other dismisses it as a limitation. The latter group has a very good point, especially when modern web applications make heavy use of JavaScript for handling UI events, querying or polling server-side APIs, processing large amounts of data, and manipulating the DOM based on the server’s response. Thanks to HTML5 and Web Workers, you can now spawn a new thread–providing true asynchrony. The new worker can run in the background while the main thread processes UI events, even if the worker thread is busy processing a heavy amount of data.

Comments

Be the first to write a comment

You must me logged in to write a comment.