3 ms·
Webpack is supposed to solve the inevitable “left-pad 2.0” problem. The downside is that each website serves their own copy of the libraries defeating cross dom
by colejohnson66 6y ago
Webpack is supposed to solve the inevitable “left-pad 2.0” problem. The downside is that each website serves their own copy of the libraries defeating cross domain caching (which browsers are starting to prevent anyways). It also requires setting up a build system. The upside of Webpack is that it does “tree shaking” which removes code that is never touched which makes the browser have to download less.
Tradeoffs...
- ratww 6y agoActually Webpack has nothing to do with the left-pad issue, and it predates it. The original left-pad problem was due to it being deleted from NPM itself. It wasn't a package served by a CDN like jQuery. Its deletion from NPM prevented people from starting new projects or re-fetching dependencies, not websites from working. And the issue of CDNs being offline or deleting packages can be solved by vendoring dependencies, which is possible without Webpack and was already the common practice for more than a decade before using CDNs for dependencies became super popular.
- colejohnson66 6y agoRight, my bad! I forgot that left-pad wasn’t a CDN issue, but a removal from npm... I think the big problem with JavaScript isn’t necessarily npm, but JavaScript’s abysmally small standard library that leads to situations like left-pad. Including left-pad into your project is easier than searching how to do something that JS’ stdlib doesn’t have. That doesn’t mean there aren’t dumb packages like `is-array`[0] that are nothing more than `Array.isArray` with a polyfill[1] for those working with Chrome 4 or earlier. Even IE9 has `Array.isArray` according to MDN![2] And that package somehow had 59,000 downloads this past week?! [0]: https://www.npmjs.com/package/is-array https://www.npmjs.com/package/is-array [1]: https://github.com/retrofox/is-array/blob/master/index.js https://github.com/retrofox/is-array/blob/master/index.js [2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...