Shimport: Use JavaScript modules in all browsers, including dynamic imports
github.com
github.com
Things like RequireJS have certainly served people perfectly well, but they're just systems that folks came up with and implemented in userland rather than any official standard – you will always need a library to use them.
Although you are correct that the WHATWG HTML spec requires implementing the import() proposal if JavaScript is supported.
Does it work in IE9 (still relevant since it is mandated by certain governments)? The GH README has no statement of browser support.
It also says that the two browsers that don’t support promises are IE and Opera Mini. [2]
That seems like an issue if this needs promises.
Firefox doesn’t currently support dynamic imports and I’m not sure Edge does either, so maybe that’s the use case for this? Or if someone is locked into an older version of Chrome or Safari for some reason. But yes, all of the “major” browsers support modules for the most part.
I wasn’t looking up dynamic imports. I guess that’s the thing that makes this library useful.
I agree with your technical assessment, but I'd put it: just add a Promises polyfill and it's compatible with IE9.
This is of course assuming someone is paying you large amounts of money to make a website that works on IE in 2018 - the gulf is so huge these days between the 4 major evergreens that's a bunch of extra work, but if you have a customer with fat pockets, then be my guest.
Edit: you added something about governments - which governments require IE9?
I don’t disagree. It just wasn’t clear if the parent was looking for “native only” support or support with polyfills. Though given that this library itself is basically a polyfill I don’t see that really being an issue.
It seems REALLY weird to me to have a project advertise it self as “in all browsers“ and then never actually specify what browsers it works in.
oh god the horror. using EVAL AND not escaping the input. Can't you just check presence of `require`?
> Note: Although import() looks like a function call, it is specified as syntax that just happens to use parentheses (similar to super()). That means that import doesn't inherit from Function.prototype so you cannot call or apply it, and things like const importAlias = import don't work — heck, import is not even an object! This doesn't really matter in practice, though.
Using eval (or the Function form of it in this case) doesn't seem like a huge issue here, because if you're accepting a user-supplied `src`, it doesn't have to contain any malicious syntax escapes in the `src` string itself to do whatever it wants...they could just supply a perfectly normal script URL of their choosing that will be executed anyway.