Delaying execution of modules in the loader

Ian Hickson ian at
Mon Aug 18 13:24:14 PDT 2014

It would be helpful if there was a way that the module _execution_ (after 
it's been parsed and dependencies have been extracted) could be delayed 
by the loader.

Suppose a page is loading and has reached a quiescent state, and so the 
browser thinks "ok, time to preload some scripts". It might start with one 
script, and then find that it imports another, and would then fetch that 
one. But it doesn't want to actually execute anything, because the scripts 
haven't been invoked yet.

Since ES6 does all the heavy lifting of finding the imports in the source 
code and setting up all the linking, it would be good if the browser could 
rely on that but just put a stop to the final execution step until such 
time as the resource is actually needed.

This would also allow for ES6 import syntax to be used inline to declare 
some dependencies, as in:

   <script type=module when-needed>
     import "jquery";
     import "jquery/animations";
     import "myapp/logic";

If the browser could notice that this was an inline script and have the 
ES6 module system pre-parse it to discover the imports, it could preload 
them and then when the <script> element's execute() method is invoked it 
could just unblock the execution and immediately have the scripts run.

Ian Hickson               U+1047E                )\._.,--....,'``.    fL       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the es-discuss mailing list