4 ms·
Question from a new JS developer: Should I be using NPM to manage my dependencies? I have recently started getting into JS programming. I have thus far avoided
by doctoboggan 7y ago
Question from a new JS developer: Should I be using NPM to manage my dependencies?
I have recently started getting into JS programming. I have thus far avoided NPM, because I've been trying to use CDNs for all my external dependencies.
My thinking is that it saves me bandwidth costs and potentially saves my user's bandwidth as well if they get a cache hit.
I get the downsides are that I don't control the CDN and they could go offline, but honestly I expect I am much more likely to go down from some mistake in my own deployment rather than a well known CDN being offline.
I am wondering if I am missing something though, because absolutely every JS package I read about suggests you use NPM (some also link a CDN, many don't). Should I be using NPM to manage my JS dependencies instead of using CDNs?
- giantDinosaur 7y agoIIRC it turns out the cache hits from CDN'ed Javascript files ended up being fairly low and neglible, due to how many different versions there are of everything. Better just reduce the file size.
- doctoboggan 7y agoI feel like bootstrap and jquery stand a decent chance of being caches in a large enough portion of the user base. And even ignoring my user's bandwidth, it would still save me significant bandwidth (depending on the size of my website). I guess eventually your site might grow such that your dependencies are not a significant portion of your total download size, but I am not currently there.
- giantDinosaur 7y agoDo you 'feel like' or do you actually know? It's important to make decisions based on actual data. I haven't researched it in depth, but if these asset sizes matter to you, then it is worth researching.
- lioeters 7y agoPersonally, I only use external library CDNs during early stages of development, or quick prototypes. There are advantages to having all needed assets locally. The main point for me is to minimize external dependencies during runtime - fewer points of failure. Also, vendor libraries can be a single minified bundle served from the same domain. In production they can be moved to a CDN, i.e., CloudFlare. Using NPM makes sense once you start having more than a few dependencies, or a build step. On the other hand, if you can get by with library CDNs and don't feel the need for NPM - I'd say that sounds fine, to keep it simple and practical.
- armatav 7y agoGood luck not using NPM - it's completely pervasive. CDN should be used in certain contexts, for everything else you're best off using NPM.
- doctoboggan 7y agoIn which contexts should I use CDNs and why am I otherwise better off with NPM?
- ehnto 7y agoIf you can afford to load an image, you can afford to send a JS file. Compile all your JS in to one file and host it yourself. The original sell for JS CDNs was that the library would already be cached from the user visiting another site, and that it would serve it from a local edge. It's really not that big of a sell, and comes with a bunch of risk. CDNs are far less reliable than my own site, and if my own site is down it's not much help that the CDN is up. Pull in two libraries from CDNs and suddenly you have three points of failure instead of one. Their traffic spikes become your traffic spikes, their downtime is your downtime. And for what? The possibility that maybe the user had that one tiny js library cached, or that the CDN has a node 100ms closer? Not worth it.