Should I host jQuery Library, fonts, etc or should I just link them from external websites like Google Fonts, etc?

9    18 Jan 2016 15:32 by u/fujin

I don't know what the benefits are for doing either of these, I usually use an external source like jQuery from Google since they would always have the most up to date library, but is there a benefit to hosting this on my own site? If anyone could give me the pros and cons and what the best practice for this would currently be.

Thanks in advanced

edit: Thanks for all the quick replies! @elcob32 mentioned third-party tracking when using external hosts which is something I did not consider and is a concern for me (especially when they're used for profiting off of my user-base!)

7 comments

5

I recommend using a CDN, the benefit is that if a visitor has already visited another site using the same CDN those assets are cached, also you save yourself the bandwidth; and browsers commonly limit themselves to two simultaneous connections per domain when loading assets. Having some of your assets at another location can help parallelize your load time.

5

There are pros and cons of both options, and even some additional options.

If you are concerned with bandwidth, and storage space then you may want to call them from an external source.

If that is not a problem then you may prefer to host them yourself which may be be slightly faster since it does not require a second server be contacted for resources.

Also if you link to them on a third-party server that third party will have an additional data point to track your websites users, which may or may not be an issue depending on your users and content.

8

I've started downloading these kinds of assets and hosting them myself for the last reason. I don't want to contribute to the routine spying companies like Google engage in every day. If people can visit a website I built without any major web tracker recording their visit, I'm a bit happier. There also isn't much benefit to linking to external hosts for these files.

2

Except the files may already be in the users cache and thus reuire no download.

3

As everything on the internet, just about everyone is wrong.

Do both.

//pseudocode
script src='your cdn and script of choice' /script
script
    if(!(jQuery)) //jQuery failed to load from the CDN...
        //create script element with src='local copy of script of choice'
/script

Theres even better options and ways to do this, but thats the general idea : CDN for speed / bandwidth gains, with a local fallback option on fail.