Enable dart2js to split output into N files to reduce initial download size #3940

DartBot opened this Issue Jun 29, 2012 · 19 comments


None yet

7 participants

DartBot commented Jun 29, 2012

This issue was originally filed by andreb...@gmail.com

When using dart2js the generate javascript contains everything required to run the code, but sometimes the application don't need to use the entire code to execute.

An example:
  load the std library and mainPage.dart
  load only the configPage.dart code and use the rest that was loaded
in the mainPage

The idea is to have something similar to what is done in GWT (with runAsync) and closure-compiler (with modules).

kasperl commented Jul 6, 2012

Added Area-Dart2JS, Triaged labels.

kasperl commented Sep 3, 2012

Added this to the Later milestone.

kasperl commented Oct 17, 2012

Removed this from the Later milestone.

kasperl commented Oct 17, 2012

Added this to the Later milestone.

kasperl commented Jan 29, 2013

Set owner to @peter-ahe-google.
Removed this from the Later milestone.
Added this to the M3 milestone.
Added Accepted label.


Removed Priority-Medium label.
Added Priority-High label.


Progress so far:

API proposal for deferred loading: https://codereview.chromium.org/11784018/

Compiler API changed to support multiple output files using Sinks/Streams (committed r17749).

Implemented deferred loading of static/top-level functions: https://codereview.chromium.org/12033003/

Missing: deferred loading of classes.


Added Started label.


Removed this from the M3 milestone.
Added this to the M4 milestone.


I have landed the CL with the API (r18637), and the CL for deferred loading of static/top-level functions (r18671).

I'm still working on deferring load of classes.


Thanks, where is this documented? A quick check of the spec didn't come up with anything.


There is a new class called DeferredLibrary in dart:async. I don't know where to find up-to-date bleeding_edge documentation, so I cannot give you a link to it.

But this feature is nowhere near complete, please don't announce anything yet.


For those following along at home: http://api.dartlang.org/docs/bleeding_edge/dart_async.html

Don't worry, just following along. Excited!


https://codereview.chromium.org/12224010 implements deferred loading of classes.

I'm aware of the following major short-comings that will persist after CL 12224010 is landed:

* The deferred code will often force Isolate.prototype to become a "slow" object. This means that calling top-level or static methods that have been lazily loaded becomes really slow (this also applies to Dart constructors).

* Only the library that is marked with DeferredLibrary is deferred. Instead, we need to perform something like tree-shaking to ensure that stuff only used by the the deferred library doesn't get included in the main JS file.

* Constants using deferred classes are broken.

* You can split the output in at most two files.

All these limitations are short-term, and I'm working on eliminating them. However, I think that once CL 12224010 lands, people can start using this for real apps.


Deferred loading of classes landed in r18834, and deferred loading of constants landed in r19378.

I'm currently working on computing the transitive closure of deferred libraries to ensure that the initial download doesn't include stuff only needed by a deferred library.


https://codereview.chromium.org/12525007/ implements basic dependency graph segmentation. This means that the initial download should not be polluted with unneeded code from shared libraries.


Submitted CL 12525007 as r19793. The compiler will now segment the dependency graph. This should make the initial download much smaller.

dgrove commented Mar 21, 2013

Added C1 label.

DartBot commented Apr 9, 2013

This comment was originally written by @seaneagan

The "You can split the output in at most two files" limitation is what I am hitting right now. I am trying to split it into about 170 files. My code is at:


Each of the 170 correspond to libraries which contain plural rules code for given locales from this directory:


Will this amount of files ever be possible/performant? If yes, I'll create a separate issue to track support for more than 2 files. If no, that would be a regression from JavaScript, where this is commonly done.

@sigurdm sigurdm was assigned by DartBot Apr 9, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment