Downloading Libraries (Pros and Cons)

Hello all

I’m plugging along in my 3rd month and I’ve just finished the weather app but I want to start using github and getting a little bit more serious about this stuff so my question is should I start trying to download add-ons/libraries like jquery, bootstrap and other thing that make coding easier. I see on a lot of people’s gits they have folders with css/jquery etc. Up until now I’ve been linking to these libraries but I was wondering if there are any benefits to actually hosting some libraries on my computer as opposed to linking. One thing I thought of was it might be better to host myself because if a link (to jquery for example) becomes outdated a lot of my code won’t be valid right? On the other hand I’m new to this stuff and I don’t know if I need a familiarity with the source code to be able to access it from my local server? Any advice (about libraries/github etc.) would be appreciated.

Cheers!

let’s say you want to customize Bootstrap and use this link

You need to download the code to do so…

If you want to get the full ability to use Semantic UI, for instance…

using it with your own build tool requires downloading it as well… and their get started page just assumes you will download it

it’s really up to you but eventually you might want to change the code in any tool or library you use…

Side note, there’s a local group of people from fCC working on a framework as well… discussed here and code is here

In your case there is no reason to download libraries locally over using cdn.
There are some cases when it’s needed to download the files. For example you want to use bootstrap source code to create custom build. Or you use a build system like grunt/gulp/webpack to compress your dependencies into one file. As I understand it’s not your case.

There are pros and cons to both approaches, and some people have an almost religious devotion to one or the other.

Reasons to host yourself

  • You can ensure that all code will be hosted. Sometimes CDNs go down. Sometimes, the user can’t access them.
  • Cache busting: you can lump all third party JS into one file that the browser can cache. This also means fewer total HTTP calls
  • Downloading the code is required for complete customization (as @DarrenfJ has shown)
  • Your code will always be available. There are dangers to relying on third parties to host code that your application depends on.

Reasons to link externally

  • It is faster. CDNs are fast and have servers all over the place. The user’s browser can almost always download the code faster from a CDN.
  • Caching. If everyone linked to the same CDN for jQuery, the browser would only have to download it once and then it’s cached for every other site that calls for the same version.
  • Less for you to do. You don’t have to manage more downloads or minify other people’s code. Just link and forget.

There are probably some other reasons that I’m forgetting. Privacy was one thought, but in practice I don’t think it’s much of an issue as you can include tokens that can be used to assert the script’s integrity. When I’m developing locally, I like to have my scripts locally hosted (usually just downloaded via NPM). If you’re already using a build system, it’s easy enough to specify whether you’re building for a development or production environment, and using this setting you can switch between a local and remote set of scripts in your HTML. Here is an example of that at work using EJS.

2 Likes