How HTML5 Web Workers improve web browsing

A common problem faced by web users is the browser freezing up when using heavy web applications. Often one has to wait for a long time till the operation completes before going any further.

With the introduction of the HTML5 Web Workers API, users can now say goodbye to this issue. The Web Workers API enables users to perform any number of tasks on a web page without those long pauses. The web page remains responsive and users can browse normally while multiple tasks run in the background.

So, What are HTML5 Web Workers?

According to the HTML5 Specifications, the HTML5 Web Workers specification defines an API that allows web application creators to launch background workers running scripts in parallel to their main page. This allows for thread-like operation with message passing as the coordination mechanism. This is similar to how we use multiple applications on our computers.

Users can go about their work without having to wait for each task to complete before going on to the next one. This HTML5 feature works with a JavaScript file performing tasks in the background without affecting the user interface.

For example a “thread” will be completing a complex mathematical calculation in the background while you are busy typing or scrolling down the web page to read something. Even better is the fact that the results are updated as the sub-tasks get completed enabling multiple threads to be run at a time without causing any information backlog.

Some technical details

Web Workers are heavy-weight scripts and not intended to be used in large numbers; another reason being that they have a high start up as well as per-instance use costs.

There are two kinds of workers; dedicated workers which are linked to their creator and shared workers which as the name suggests are scripts with common origin and ability to communicate with similar ones.

As the Web Worker API runs in a separate “thread” it does not have direct access to the webpage’s Document Object Model (DOM). The worker “threads” therefore communicate with the web page from which they originate by way of call back functions and message strings to effect any changes.

Compatibility and support

Currently the Web Workers API is supported in Mozilla Firefox 3.5+, Apple’s Safari 4, Google Chrome 4 and Opera 10.6. As of now Web Workers is not supported in any version of IE, including the beta IE9 version released on September 15, 2010.

TAGS > , , ,