Do you/should you load jQuery from Google CDN?

by 10 comments
If you load jQuery from the local server there is no chance of waiting for the 3rd party site, but little chance the end-user already has it cached in their browser.

Some people are convinced getting it "free" from Google is faster, others say "can be extremely slow", and there is also the option of getting it from jQuery's site.

Does anyone know if the CDN uses Amazon web services, and/or do they have a "perfect record" of up-time?
#programming #cdn #google #jquery #load #you or should
  • Profile picture of the author oldschoolwarrior
    I was just creating a php javascript loader, and found that the using googles compressor, really is slow.

    Closure Compiler Service

    Was talking about 30 seconds to load, and minimize code.
    I download jquery, and ran it though my own php loader, to use caching and gz compressions, and it works great now!
  • Profile picture of the author Tony Martinez
    I load jQuery from Google's CDN, but with a local fallback in the odd event that Google's copy doesn't load. The following is a model of what I have in my HEAD. I load the script from CDN first, then immediately check if jQuery is defined. If it's not, then my local fallback loads. Probably not the best fallback solution, but it works for me.

    <script src="//"></script> 
    <script>window.jQuery||document.write('<script src=""></script>')</script>
  • Profile picture of the author wayfarer
    Just load it from Google. If it's good enough for Twitter, it's good enough for me.
  • Profile picture of the author Damien Roche
    Just to offer another option, I minimise and concatenate all javascript (and css) into a single js/css file.
  • Profile picture of the author SteveSRS
    depends if you are using your own CDN...

    If yes don't... only creates extra DNS request which is a bad thing..
    If no.. depends test it.. I actually usually load it from my own domain.
  • Profile picture of the author Don Art
    No question you should load from Google (second choice from jquery).

    Do not load from your host.

    Here's why with proof:

    if your visitor's browser follows http1.1 recs it will only open 2 simultaneous connections to any one host name at a time - so multiple hostnames is actually better:

    "Clients that use persistent connections SHOULD limit the number of simultaneous connections that they maintain to a given server. A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy. A proxy SHOULD use up to 2*N connections to another server or proxy, where N is the number of simultaneously active users. These guidelines are intended to improve HTTP response times and avoid congestion."

    Loading content from multiple hosts is generally better for another reason, if a server is slowish, content is still able to be fetched via the connections to the other specified hosts.

    From Yahoo's Performance Best Practices:

    "Reducing the number of unique hostnames has the potential to reduce the amount of parallel downloading that takes place in the page. Avoiding DNS lookups cuts response times, but reducing parallel downloads may increase response times. "

    Note too: The issue of dns lookup time is mitigated by the fact that the user or user's ISP is extremely likely to have cached the domain. More from the same source:

    "DNS lookups are cached for better performance. This caching can occur on a special caching server, maintained by the user's ISP or local area network, but there is also caching that occurs on the individual user's computer. The DNS information remains in the operating system's DNS cache (the "DNS Client service" on Microsoft Windows). Most browsers have their own caches, separate from the operating system's cache. As long as the browser keeps a DNS record in its own cache, it doesn't bother the operating system with a request for the record."


    CDN technology is seriously robust and proven. Google's tech is 2nd to none. It's entire business depends on their CDN.

    Google uses it's massive CDN to deliver content from servers worldwide. There will be an edge server closer (therefore probably faster) to your visitor than your own server is likely to be.

    Finally and I think most decisive:

    The user's browser is exceedingly likely to have already cached Google's copy of jquery from a previous visit to one of the millions of sites using Google's hosted apis. This means the browser will just load a local copy - far faster than any network access.
    • Profile picture of the author Happy_Balance
      Originally Posted by Don Art View Post

      if your visitor's browser follows http1.1 recs it will only open 2 simultaneous connections to any one host name at a time - so multiple hostnames is actually better:
      Good point about multiple hostnames, I should remember to load some images from a sub-domain.
  • Profile picture of the author Michael71
    Depends on the files you are loading after jQuery.

    I prefer minifying/combining all JS files into one file.

    In that case you just need one http-request and that's from your own domain.
    Will save DNS lookup and time, same with CSS.
    • Profile picture of the author AppDeveloper
      I agree with the others suggesting loading it from Google.

      The vast majority of people will have it cached via that url. I don't have specific numbers, but with the number of sites linking to the Google version, I would be surprised if less than 95% of your visitors didn't have it cached.

      And the ones that don't have it cached are going to most likely load it quicker from Googles CDN than from your server.

      Combining all your JS files into one request is definitely a good idea, however, when that file gets too large (greater than ~64k) it makes sense to split it up into two files. If the rest of your included JS libraries are large then this can add up quickly. Modern web browsers will download multiple JavaScript files in parallel. So having two 60k files will download faster than one 120k file.

Next Topics on Trending Feed

  • 23 {{ upvoteCount | shortNum }} 5

    1. Lack Of Strategy Many of the tools available to Internet marketers are either cheap or free. As a result, many new marketers are tempted to use them all at once. Successful Internet marketers begin with a strategy that identifies the goals of a campaign, the target audience and other key planning elements. Only then do they choose their tactics. Remember: tactics without strategy is the noise before defeat.

  • 26 {{ upvoteCount | shortNum }} 5

    After five years and almost one thousand projects, give it or take, I believe I have come up with a handful of more or less reliable signs that you're dealing with a bad client. I haven't reinvented the wheel, that's for sure. It's just like in that saying. Maybe I don't know what I want, but I certainly know what I don't want. The same goes here. Maybe I don't know how to find a good client, but I certainly know how to avoid a bad one. Also, I'm far from an ideal list. Sharing experiences regarding bad clients can help a lot. After all, we play in the same team. In addition, I strongly believe in Good Karma principle. Meaning, there's plenty of room and clients for everybody. Deal with real people not with avatars

  • 9 {{ upvoteCount | shortNum }} 5

    When people think of the term copywriter they will often imagine someone sitting at home or at a caf, tapping away at a laptop and churning out good copy for their immediate employer whether it be a one-off project or a long-standing relationship between a publication (online or print) and the copywriter. Now that might often be correct, but there are different types of copywriters out there. Lets have a look at the main types.

  • 5 {{ upvoteCount | shortNum }} 5

    I've been a relatively successful Freelance writer on over the last several years. I haven'€™t worked totally consistently during that time, but I've done pretty well and have recently been growing my business pretty aggressively and turning up the heat! I recently got connected with a start-up company that frequently uses Freelance to get tasks done for cheap, and I had a great conversation with the founder of that company which serves as the inspiration for this article. Employers have to work hard to ensure that they'€™re getting the right person when they hire a Freelancer. Once a project is accepted and a milestone is created, it can be a major hassle to resolve any disputes, especially those surrounding the quality of the work. I don't have a lot of insight into this process but I have learned a thing or two about choosing the right employers. A lot of folks have it in their head that the customer is always right, but as a Freelancer, you have the ability to choose who is and isn'€™t going to be your customer. Here are some guidelines for finding great employers that fit with your business.

  • 11 {{ upvoteCount | shortNum }} 5

    Hopefully someone can enlighten me on something that I'm confused about it. So when it comes to CPM, from an advertisers point-of-view, they pay for every 1,000 impressions of their ad. Now their ad is viewed on multiple sites. So let's say it's viewed 100 times on Site A, 200 times on site B, 300 times on site C, and 400 times on site D. Once that happens, the advertiser pays. Correct me if I'm wrong, but that is how that works? From the perspective of a publisher is where I'm more confused. So if I'm displaying CPM ads on my site, am I paid everytime the ad is viewed on my site or does the ad have to be displayed 1,000 times on my site before I get paid?