4 ms·
> A hands down amazing feature, something I was pining for for so long and it is finally here. Performance? Sure, if you are building high traffic sites, you wi
by TheAceOfHearts 3y ago
> A hands down amazing feature, something I was pining for for so long and it is finally here. Performance? Sure, if you are building high traffic sites, you will still reach for a bundler, but browser ESM without a build step will allow many intranet and low traffic Internet development teams to ship much nicer code than they do now after buying into bundle-everytime voodoo. If this existed before WebPack, so much spaghetti code could have been avoided.
Before or around the same time CommonJS appeared there was another module system before Webpack existed, I think it was called Async JS. It was browser-first and allowed you to do JS development in the manner which you describe. It was also supported by Webpack's bundler. A bit surprising to see this piece of history getting memory holed.
Edit: I think it was called RequireJS? You would give it an array of dependency paths and a callback function to get executed once everything was loaded.
- tomashubelbauer 3y agoI have not heard of it but I think the main benefit of ESM over a bunch of `script` tags (what I used before CJS came about) is that the individual modules files are isolated and do not share globals which was a common pain point when using `script` tag soup and something that IMO drove a lot of people to use bundlers to avoid this who did not benefit from bundling otherwise (intranet web apps and low traffic Internet apps - their debugability went downhill and stayed there for a long time and even with the introduction of source maps and such, those weren't supported right away in all tooling). If the thing you describe solved this back then I regret not having come across it.
- TheAceOfHearts 3y agoIt's been a really long time since I last used this tool, but I think it always executed asynchronously within a callback function. So doing stuff like `var foo` wouldn't affect the global scope, since your code was always supposed to be placed inside a function call which receives all dependencies as a parameter. https://requirejs.org/docs/api.html https://requirejs.org/docs/api.html
- WorldMaker 3y agoAMD modules (the name of the types of modules that RequireJS and other loaders, there were multiple competitors) were very much a thing. (Still are in the ArcGIS world that bet heavily on ancient framework Dojo and will take years still to migrate to ESM. Though luckily for them they get to skip CommonJS altogether.) Bundlers made people forget the pains but also the useful lessons of AMD modules.