Referencing modules loaded by HTML Imports.

Ian Hickson ian at
Tue Aug 19 16:22:14 PDT 2014

On Mon, 18 Aug 2014, John Barton wrote:
> On Mon, Aug 18, 2014 at 2:06 PM, Ian Hickson <ian at> wrote:
> > > > > >
> > > > > > Now, in the main page, you reference the HTML import:
> > > > > >
> > > > > >    <link rel=import href="foo.html">
> > > > > >
> > > > > > Now how would you refer to the modules? We can't have #b refer 
> > > > > > to it, since the scope of IDs is per-document, and the import 
> > > > > > has a separate document.
> If they share a Window object then they should share a Loader, but they 
> may have different baseURLs. So for you example above we write eg.
> import {b} from "./b";
> because the scripts in the HTML import will have names relative to the same
> default baseURL as the main document.

I don't understand. Why would "b" refer to a script in the module?

Suppose you have two imports in index.html:

   <link rel=import href="foo.html">
   <link rel=import href="bar.html">

...and foo.html and bar.html both have this structure:

   <script type=module id=mod1>
   <script type=module id=mod2>

How should an import statement in index.html refer to the id=mod1 module 
in foo.html? How about the id=mod1 module in bar.html? How about the 
id=mod2 module in bar.html?

(All the files are in the same directory.)

> I think we could also imagine that such an import declaration could be 
> used without the HTML Import declaration. The fetch() call will ask for 
> "<baseURL>/foo/b.js" and the server will say "hey that's in an HMTL 
> Import" and serve text/html. The fetch() hook will have to detect this 
> and process the HTML Import, then continue with the loading process.  

That's basically what everything I've been e-mailing the list about is 
intended to support.

On Mon, 18 Aug 2014, Matthew Robb wrote:
> Would there be any problems treating the html import as a virtual module 
> itself. Giving all scripts inside the sub document the module context 
> object as its this binding? Then to do any additional loading you'd need 
> to do this.import().

I'm not sure what this means. Presumably though the browser should take 
care of this, the author shouldn't have to call this.import() or anything 

On Tue, 19 Aug 2014, John Barton wrote:
> OTOH, I think System.import() is clearer.

Not sure how this applies here.

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

More information about the es-discuss mailing list