Module naming and declarations

Anne van Kesteren annevk at annevk.nl
Sat May 4 01:12:06 PDT 2013


On Sat, May 4, 2013 at 12:46 AM, Jason Orendorff
<jason.orendorff at gmail.com> wrote:
> 0. No effort: modules are loaded relative to the document base url,
> with ".js" appended. So `import "jquery"` maps to the relative URL
> "jquery.js".

Isn't that weird? If I have a script at /resources/test which does a
bunch of imports and I use /resources/test from resources /a/b and
/c/d the document base URL will be different for both. (Document base
URL does not work for workers either.)

Appending ".js" also seems very counter to any other API in the
platform and kinda counter web architecture.


> 1. One line of code: you can set the root URL from which all imports
> are resolved. If you set `System.baseURL =
> "https://example.com/scripts/"` then `import "jquery"` maps to the URL
> "https://example.com/scripts/jquery.js".
>
> 2. A few lines: you can use System.ondemand() to set the URL for each
> module you use. If you call
> `System.ondemand({"https://example.com/jquery-1.9.1.js": "jquery"})`
> then `import "jquery"` maps to the URL you specified (imports for
> modules that aren't in the table will fall back on the loader's
> baseURL).

I thought the import statements had to be first. Does this effectively
require two script elements?


--
http://annevankesteren.nl/


More information about the es-discuss mailing list