This comment is gonna be bikeshedding, and definitely not a popular opinion in today's "modern" JS community, but here it goes anyways...<p>I don't understand why TC39 had to define a new syntax, new semantics, and new <i>restrictions</i> for modules in JS land when the JS community had <i>already</i> created solutions for modules in JS. People were using modules in JS before they knew that "loader" or "static import/exports" were a thing to be landed in ES6 in future. And frankly, what the JS community made for themselves was a lot more saner than what is coming natively to JS, and even more so compared to the native solutions for module loading in some other languages (compare to Python for example). I don't think any JS programmer wanted modules natively in JS. And with HTTP2, they would have just stopped bundling and a newer async implementation of `require` would have been conjured.<p>And all this "tree-shaking" etc. that is claimed to be possible only with the static syntax is blatantly incorrect. It is entirely possible to eliminate unused code with the commonjs/amd/umd way with a slightly more intelligent bundler. And the new "syntax" that they created is just a variant of destructuring. You can achieve nearly the same with ES6 destructuring and `require`.<p><i>sigh</i>
If you don't find JavaScript modules confusing, you should. I work on a module loader [1] and I find it quite confusing. To clarify we have 3 things:<p>1. import and export syntax, this is defined in ES2015. It's just syntax, it doesn't explain how modules should be loaded.<p>2. The Loader spec (<a href="http://whatwg.github.io/loader/" rel="nofollow">http://whatwg.github.io/loader/</a>) which defines a full loader including hooks to do just about anything you can possibly need. This allows you to do really crazy things like define modules dynamically and import then dynamically (which the static import/export syntax doesn't allow). We use this extensively in StealJS (or at least an older version of it) and it's pretty powerful.<p>3. import type=module is what this article is referring to. It defines a tag that allows you to import modules in the browser. You can't use a regular script tag, modules are different; they are strict mode by default for example.<p>If you read the GitHub issue there was some discussion of whether import type=module should use the Loader spec. It probably should. But the Loader spec isn't done so... reading the spec and seeing things like the module map [2] it sounds like import type=script defines a miniature sized loader.<p>I don't blame them for doing this, Loader has taken too long and people are clamoring for <i>something</i>. The Loader spec has a weird history; it was close to being done in ES2015 but when it was ejected it sit for a <i>long</i> time without much work. Then around last summer it was heavily worked on and got pretty far. But now as it sits, no commits like the last 2 and a half months [3]<p>At this point I wouldn't be surprised to see Loader go away. It's probably too controversially and too big to ever get done. I imagine the web will just have the import type=module loader and Node will do it's own this. This is going to make writing portable JavaScript as annoying going forward as it's always been.<p>[1] <a href="http://stealjs.com/" rel="nofollow">http://stealjs.com/</a><p>[2] <a href="https://html.spec.whatwg.org/multipage/webappapis.html#module-map" rel="nofollow">https://html.spec.whatwg.org/multipage/webappapis.html#modul...</a><p>[3] <a href="https://github.com/whatwg/loader/commits" rel="nofollow">https://github.com/whatwg/loader/commits</a>
This is huge. Finalization of the module loader spec is usually what's cited as the last remaining blocker for full implementation of modules in V8 [1]. Combined with HTTP2 being available nearly everywhere [2] and native ES6 support soon reaching most mainstream browsers [3], it means that web developers will soon be able to drop a large portion of the current JS stack, including spriting, Webpack, and Babel.<p>[1] <a href="https://bugs.chromium.org/p/v8/issues/detail?id=1569" rel="nofollow">https://bugs.chromium.org/p/v8/issues/detail?id=1569</a><p>[2] <a href="http://caniuse.com/#search=http2" rel="nofollow">http://caniuse.com/#search=http2</a><p>[3] <a href="https://kangax.github.io/compat-table/es6/" rel="nofollow">https://kangax.github.io/compat-table/es6/</a>
Can you use <script type="module"> with web components/Polymer (in a sane way, e.g. without duplicates being loaded like with the old <script> tag)?
There are many ways to load and execute JavaScript, static/dynamic adding a script tag to the html, html imports, manual fetch + eval , concatenation of javascript files in 1 file, in the future maybe the import syntax ? and now <script module> ?<p>Do we really want to add more ways ? Complexity is an enemy of security, it will add more confusion. Maybe we should first disable/remove ways to load and execute JavaScript.<p>We should also think, if what really need is a client solution or a better tool/system to transform scripts, in a script server side.<p>Why, what should be clearly answered before thinking in terms of how.<p>Sometimes having the bigger picture in your head helps.