Fwd: "delay" keyword

Patrik Stutz patrik.stutz at gmail.com
Thu Jul 5 09:26:15 PDT 2012


Ok, maybe this can indeed work. But instead of the "import x from y" I
really would make it like Isaac already suggested it:

var a = import "a.js";

I clearly see the benefit of the "load all at the start before executing
anything" strategy and like it very much. I only feared that a site could
take a very long time to load when there are big libraries used, even when
the page first only displays a login page for example and does only need 1%
of the whole code.

But I think one could solve that problem by adding a new script tag after
login that contains the next needed module. The cool/bad thing about this
is that the developer can decide by himself which modules are loaded at the
start and which modules are loaded later. Since lazy module loads are a
rare thing, it wouldn't matter if wasn't "synchronous". One should just be
able to call Loader.load('mymodule',function(module){}) in this situations.
It should also be in the spec, tough.

It would be a perfect combination of load all at once and lazy loading. It
could definitely make me happy this way. (With the API suggested by Isaac,
tough =))

2012/7/5 David Bruant <bruant.d at gmail.com>

>  Le 05/07/2012 17:19, Patrik Stutz a écrit :
>
> BUT: interestingly, the import keyword also seems to be synchronous. So, I
> think behind the scenes there still would have to be something like a
> "delay" function to make it non-blocking. Or am I missing something?
>
> The 'import' keyword is synchronous, but in a different than node.js
> 'require':
>
>     var a = require('a.js');
>     var b = require('b.js');
>     var c = require('c.js');
>
> Here, a.js is fetched, parsed and executed, then b.js is fetched, parsed
> and executed, then c.js is fetched, parsed and executed. In that order
> sequentially.
>
>
>     import a from 'a.js'
>     import b from 'b.js'
>     import c from 'c.js'
>
> Here, a.js, b.js and c.js are fetched and parsed in parallel, but executed
> in the order they are declared. If other imports are found in parsing
> phase, these can be fetched and parsed in the background.
> The most important part being parallel and in depth fetch since network is
> the performance bottleneck in web applications.
>
> If you want delayed module loading (with a custom delay), you can always
> fetch the scripts yourself and eval them.
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120705/38946d60/attachment-0001.html>


More information about the es-discuss mailing list