We are happy to announce the alpha release of WorkerDOM – a JavaScript library that makes the Document Object Model (DOM) available to Web Workers. This allows web developers to take advantage of pervasive multi-core processor architectures when programming their web pages to make them more performant. While the WorkerDOM library is designed for general web programming, we plan to use it in the AMP Project as well, which we will detail more below.

The underlying Web Worker API has been available to web developers for almost a decade, but it hasn’t seen widespread adoption. One of the reasons was that the primary API for manipulating web pages, the DOM, was not available inside of workers. WorkerDOM changes this, thereby enabling developers to more easily port their existing applications. We hope that this will spur renewed interest in multi-threaded programming on the web, and lead to much better experiences for users down the road.

Our research has shown that single-core CPU performance for low-cost devices has not significantly increased over the last years. As a result, from a single-core point of view, mobile devices have gotten cheaper but not faster. There is significant opportunity to take advantage of the extra cores that even the least expensive CPUs provide that aren’t available to JavaScript programming by default. To make web performance truly competitive with that of native platforms, we should try to unlock this extra bit of performance to provide better and more modern experiences across the whole range of devices people use.

Not all mobile devices are created equal.

WorkerDOM aims to provide a full representation of the DOM inside of Web Workers. In the ideal case this means that scripts can be used unchanged inside of the worker environment. At the heart of the library is an efficient transport mechanism written in TypeScript. It hydrates server rendered DOM and then proxies mutations as an application makes changes to the page, such as reacting to user actions or running animations. For more details about the inner workings of the WorkerDOM library and possible use cases, please check out the slides from our presentation at JSConf US 2018.

As announced at the AMP Conf 2018, the AMP Project is working on a long-term effort to make JavaScript programming available to AMP page authors. The WorkerDOM library is central to this initiative and we’re excited to incorporate it into AMP later this year. WorkerDOM is compatible with frameworks such as React, Preact, and Svelte — and more are on the roadmap. We’re super excited to see all of these frameworks used in creating AMP pages in the future!

Today’s release is an alpha release. WorkerDOM is ready for experimentation but not yet ready for widespread production use. We’d love to collaborate with framework and tool authors to ensure compatibility and great developer experience when using WorkerDOM in as many places and contexts as possible!

Kristofer Baxter, Software Engineer at Google