Monday, 10 October 2011

HTMLConverter for DART

To make it easier to develop web applications in Dart, we propose adding a new mime type (application/dart) for HTML documents that allows embedding dart scripts. We wrote a script (htmlconverter.py) that will translate an HTML page with these new mime types into an HTML page with JavaScript code.

Using htmlconverter.py

To invoke this script, ensure that you have a checkout of the project, and that you have built the dartc compiler (see instructions in Building).
Then you can invoke the script as follows:
$ python dart/client/tools/htmlconverter.py input.html -o out/
The script will do the following:
  1. Invoke the dartc compiler on any code in the page, embedding the result on a script tag.
  2. Inline any css code
  3. Within css, embed images as a data-url using a base64 encoding.
If all images in your app are referenced from css files, the end result is a monolithic html file that can be used to deploy your application. The Dart code in your page will be executed asynchronously when the browser triggers the DOMContentLoaded event.

Work in progress

The following is still pending to be implemented in htmlconverter.py:
  • Support heavy isolates: currently the tool inlines all script tags in the html page. Heavy isolates can only be spawned from scripts that are loaded via a URL (a restriction derived from web workers).
  • Implement support for multiple isolates in the HTML page. This includes:
    • Allow multiple script tags in a page, mapping each script to an isolate.
    • Introduce an isolate discovery mechanism (e.g. a registry), so that top-level isolates don’t have to use window.postMessage to communicate.

No comments:

Post a Comment