Skip to content

Comment on Install NPM dependencies that run in browser without Browserify, Webpack

Comments

HTTP2 solves the loading multiple dependencies in parallel part of the equation, but as far as I can see, the browser would still have to download each dependency before they can resolve their transitive dependencies, so wouldn't this suffer latency issues due to requiring as many sequential client-server roundtrips as the max depth of your dependency tree?

SystemJS & JSPM has been around for quite a while now, and the goals are similar to this project (to enable loading of any NPM dependency as native ES modules in the browser). They solve the roundtrip problem using an import map that's generated by JSPM to pre-resolve all transitive dependencies, so they can be loaded by the browser up front with maximum parallelism.

However, this project specifically calls out the lack of a need for an import map in its description as an advantage, so I'm wondering if they have some alternative solution to this problem.

Also somewhat related: the project maintainers for SystemJS and JSPM also provide a CDN at https://jspm.io/ serving jspm packaged ES modules for all npm packages, so you can load them as native ES modules with a module script tag or native dynamic import() call in supported browsers. But they specifically mention that this CDN is meant for quick prototyping/experimentation, and not suitable for production use due to latency issues, and recommend bundling workflows for production.

I've been following the SystemJS and JSPM projects for quite a while now, and I feel it's a much better solution for module loading than webpack and the likes that hack together their own non-interoperable proprietary module loader rather than supporting and advancing the official ES module loading standard. But unfortunately that's where the community is at, and SystemJS and JSPM has never been able to reach that critical mass of essential dev tooling that webpack & others have enjoyed for quite some time (the major road block I ran into the last time I tried it was the lack of a good hot module replacement story for development targeting the latest SystemJS 2.0 environment).

the browser would still have to download each dependency before they can resolve their transitive dependencies.

The endgame of that train of thought is something like https://mariusgundersen.net/module-pusher/

Indeed, and it can even be done with HTTP/1: https://jacquesmattheij.com/the-several-million-dollar-bug/

tl;dr: a smart server can start pushing dependencies as soon as the request for a module comes in.

Even with HTTP/1, the browser will handle a response that came before the matching request.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.