Delaying execution of modules in the loader

Guy Bedford guybedford at
Tue Aug 19 11:55:09 PDT 2014

The loader is designed to enable deferred execution, but there isn't an
easy hook to allow this that I know of.

System.define is the only load function that does not ensure execution. The
others (System.import, System.load, System.module), run an EnsureEvaluated
call to run the scripts.

It could certainly be worth considering a new load function that runs the
hook cycles but does not evaluate - System.preload for example. The
implementation is trivial as well.

On 18 August 2014 13:24, Ian Hickson <ian at> wrote:

> 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";
>    </script>
> 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.   `._.-(,_..'--(,_..'`-.;.'
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list