News for hackers. Stuff that matters.
Re:Microsoft Edge supports ES6 modules by MatthewPhillips on Tuesday May 17, 2016 @02:33PM (#11716084)
For those thinking about using this, it bears mentioning that there are a few caveats to script type=module that makes it difficult to use with a lot of modern workflows, namely:

1. No way to dynamically import a module (the article explains this).

2. All imports must be relative or absolute urls, so either ./foo.js or /foo.js or http://example.com/foo.js

This means you can't npm install lodash and import the string "lodash".

3. All imports must include the file extension (.js). So even if you set up a server route for /lodash it would break as soon as one of lodash's imports didn't use .js (or it imports another package). This is assuming lodash is written with import/export; it's not so it wouldn't work at all.

4. Until http2 comes around, this is probably not something you want to ship to production (unless you have a small app with only have a handful of scripts being imported), so bundlers are here to stay for a while.

It might be possible to work around 1, 2, and 3 using Service Workers, I wrote about this a while ago: https://matthewphillips.info/posts/loading-app-with-script-m...

Re:Microsoft Edge supports ES6 modules by silverwind on Tuesday May 17, 2016 @03:11PM (#11716438)
> All imports must include the file extension (.js)

Or, .mjs [1].

[1] https://github.com/nodejs/node-eps/blob/master/002-es6-modul...

Re:Microsoft Edge supports ES6 modules by nacs on Tuesday May 17, 2016 @10:02PM (#11719210)
> .mjs [1].

I was worried this was short for "Microsoft JS", thanks for the link.

Re:Microsoft Edge supports ES6 modules by WorldMaker on Tuesday May 17, 2016 @03:56PM (#11716833)
The article doesn't mention 2 and 3, but just as with 1 the module loader spec that is not yet implemented would also happen to help address 2 and 3 by providing plugin mechanisms to support name mappings like automatic file extensions and mapping canonical module names like 'lodash' to file paths.
Re:Microsoft Edge supports ES6 modules by MatthewPhillips on Tuesday May 17, 2016 @04:12PM (#11716986)
Just to clarify, the mappings for names to paths isn't enough to load an NPM-based project. With NPM you can have multiple semver-incompatible packages. It's very common to happen, actually.

For example, you might depend on "foo" and "bar". "foo" also depends on "bar", but it needs version 1 and you need version 2. In this case, setting paths for "bar" won't work, the paths are different for each parent.

The loader spec provides a hook "resolve" that allows you to work around this, just wanted to point out that configuration alone wouldn't be enough.

It's also worth noting that the Loader spec doesn't have a real urgency to it. What I mean is that likely browsers will implement script type=module first, give it some time to brew, and then pull in things from whatwg/loader over time. In the meantime we'll want solutions that do allow us to use script type=module and still have modern workflows we are used to.

Re:Microsoft Edge supports ES6 modules by WorldMaker on Wednesday May 18, 2016 @09:49AM (#11721887)
I would hope that the Loader spec gets a bit more urgency as developers bump into the limitations of script type=module.
Re:Microsoft Edge supports ES6 modules by toomanythings2 on Tuesday May 17, 2016 @04:41PM (#11717231)
Until http/2 comes around? I've been using it for a couple of months on all our client sites and the standard was finalized last year. It's now available in all current, major browsers.
Re:Microsoft Edge supports ES6 modules by hyperknot on Tuesday May 17, 2016 @06:29PM (#11718109)
Please have a look at the data before writing such statement. In the latest CloudFlare article [1] about it (Feb 2016), they concluded that only 52.93% of their users are connecting over HTTP/2.

[1] https://blog.cloudflare.com/cloudflares-impact-on-the-http-2...

Re:Microsoft Edge supports ES6 modules by toomanythings2 on Tuesday May 17, 2016 @07:50PM (#11718591)
Which statement? All major browsers can work with it. Apache and nginx, at least can also work with it (encompassing 85% of all internet servers).

That users aren't connecting to http/2 web sites is no indicator that http/2 is not available.

Re:Microsoft Edge supports ES6 modules by hyperknot on Tuesday May 17, 2016 @07:59PM (#11718635)
Like any Internet Explorer on any non-Windows 10 systems?

If 47% of all CloudFlare users are not connecting via HTTP/2 (even though it is supported server side), I believe it means that those users do not have client side support (or are behind a proxy, etc. which doesn't allow it).

At the end, if someone is thinking about making a website which would be much slower for non-HTTP/2 users then right now it means around 47% of their users.

Re:Microsoft Edge supports ES6 modules by toomanythings2 on Tuesday May 17, 2016 @08:59PM (#11718942)
I said "all current, major browsers" in my original post. IE is not Microsoft's current browser. In addition, not all web sites are serving via http/2 and that web sites aren't using http/2 is no fault of the browser or the user.
Re:Microsoft Edge supports ES6 modules by nostrademons on Wednesday May 18, 2016 @12:17AM (#11719696)
The conclusion of that blog post was that you should enable HTTP2 on your site.
Re:Microsoft Edge supports ES6 modules by exclusiv on Tuesday May 17, 2016 @06:35PM (#11718155)
Nginx and other servers handle both automatically no?
Re:Microsoft Edge supports ES6 modules by hyperknot on Tuesday May 17, 2016 @06:41PM (#11718206)
Yes, but the problem is on the client (browser) side.
Re:Microsoft Edge supports ES6 modules by toomanythings2 on Tuesday May 17, 2016 @07:47PM (#11718573)
I am not aware of any current major browser that does not support http/2. http://caniuse.com/#search=http%2F2