On Wed, Aug 13, 2014 at 3:52 PM, Ian Hickson <i...@hixie.ch> wrote:

> On Wed, 13 Aug 2014, John Barton wrote:
> > On Wed, Aug 13, 2014 at 2:59 PM, Ian Hickson <i...@hixie.ch> wrote:
> > >
> > > Suppose a page has this markup:
> > >
> > >    <script type=module id=jquery href="jquery.js" whenneeded></script>
> > >    <script type=module id=a href="a.js" uses="jquery"
> whenneeded></script>
> > >    <script type=module>
> > >     import "a";
> > >     // ...
> > >    </script>
> >
> > Your example will just work if you just use
> >
> >    <script type=module>
> >     import "a";
> >     // ...
> >    </script>
> >
> > When this module is compiled the other two will be loaded and compiled.
>
> That assumes that you have some sort of server-side support so that the
> server knows that when you request "a", it should send "a.js" and
> "jquery.js", which is an assumption that will work for some people but not
>

No, the loader just requests each of these when it needs them.


> everyone. One of the big pieces of feedback I am dealing with on the HTML
> side is a request for a way to predeclare the dependency graph to avoid
> this problem (so that the browser knows to request a.js and jquery.js at
>

Actually I guess you mean "avoid multi-pass requests for the entire
dependency graph".


> the same time). People apparently have huge difficulties even getting
> their servers configured to send the right MIME types, let alone getting
> the servers to know about dependencies.
>

Yup.


>
> (If you don't have either server-side support or client-side dependency
> predeclaration, you end up having to discover the dependency chart at
> runtime, which is a huge latency loss.)
>

Well, as they said back when I worked on a dairy, "you've step in it".

This issue is at the root of the split between commonjs (modules for node,
synchronous loading) and requirejs (modules for browser, prebuilt into
bundles to avoid latency). The ES module system attempts to solve this by
providing an asynchronous API (eg System.import()) and a proposal, to
support server side dependency bundling in HTTP++.

The workaround we have now is to pre-build bundles and use the locate()
function to map module ids into bundles.  That is basically the requirejs
solution (with a much better programmer API).  I predict node will extend
their System to include a synchronous API. Then the circle will be complete.

To be sure this is a difficult or even fundamental problem. I respect all
efforts to solve this problem; don't believe anyone who says the solution
is simple.

jjb
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to