should external http files be loaded for website optimisations

时间:2015-05-24 20:37:32

标签: jquery ajax

I notice when developing my website that it does take a few seconds to load the following files that i use for my site and wonder if I should make a local copy of these and integrate them into my web folder as standard like my other files i have developed.

I am aware that there are many opinions out there but frankly Stackoverflow is home to me and want the responses to be out there for everyone else from here.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

        <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>

<script type="text/javascript" src="http://oss.maxcdn.com/libs/modernizr/2.6.2/modernizr.min.js"></script>

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">

it is probably worth noting that google and many other "well known" servers do actually have downtime especially when it comes to dns... i know it is a different ballgame but worth noting...

a lot of people also have the argument that if something is closer to local as possible this is always going to be better. this is not necesarrily my own opinion though

1 个答案:

答案 0 :(得分:2)

There are many reasons why one would chose a CDN over local hosting, and vice versa, lets cover a few of them:


CDN Hosting

  • You save space on your local drive ( often not much, but many libraries can add up, I mean jQuery is nealry a megabyte )

  • A CDN service will pick a server local to the specific user, whereas your server is in a set location, hence less distance for the data to travel and so faster download speeds

  • A CDN is likely much faster at serving the statics than your own server, mostly since they are hosted by large corporations (need I say more?)

  • Most CDN services keep their files and libraries up to date all the time

  • Using a CDN will save you money on bandwidth, though it sounds like a near irrelevant point for only a few kilobytes it can add up... ( jquery is 95KB; *1000 visitors = 95MB AKA a lot )

  • Since many sites use CDN's, your visitors will likely already have the file in cache from having visited another site, meaning no download is required; thus saving time.

Local Hosting

  • You have full control over the exact contents of the files, i.e. you can edit the files if you want

  • You only need your server to be up in order for your site to work, without relying on another aswell

  • Some countries aren't allowed to access certain domains, ( North Korea, Iran, Syria & Cuba all can't access Google, nor its' CDN )

  • Easy to remember filenames, like /js/jquery.js, instead of massive URL's

Personally I use local hosting for production, then go to CDN when I release it, I think that using a CDN is the way to go, especially with the massive bandwidth saved... Of course it is all your choice, but I (like many, many others) recommend to use a CDN. On that note, I suggest MaxCDN and Cloudflare CDN