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 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.

Next Topics on Trending Feed