Microsoft CDN for jQuery or Google CDN?

65,011

Solution 1

Update based on comments:

Short version: It doesn't matter much, but it may depend on what they host. They all host different things: Google doesn't host jQuery.Validate, Microsoft did not host jQuery-UI, since 2016 they do!!, Microsoft offers their scripts that would otherwise be served via ScriptResource.axd and an easier integration (e.g. ScriptManager with ASP.Net 4.0).

Important Note: If you're building an intranet application, stay away from the CDN approach. It doesn't matter who's hosting it, unless you're on a very overloaded server internally, no CDN will give you more performance than local 100mb/1GB ethernet will. If you use a CDN for a strictly internal application you're hurting performance. Set your cache expiration headers correctly and ignore CDNs exist in the intranet-only scenario.

The chances of either being blocked seems to be about equal, almost zero. I have worked on contracts where this isn't true, but it seems to be an exception. Also, since the original posting of this answer, the context surrounding it has changed greatly, the Microsoft CDN has made a lot of progress.

The project I'm currently on uses both CDNs which works best for our solution. Several factors play into this. Users with an older browser are still probably making 2 simultaneous requests per domain as recommended by the HTTP specification. This isn't an issue for anyone running anything decently new that supports pipelining (every current browser), but based on another factor we're knocking out this limitation as well, at least as far as the javascript.

Google's CDN we're using for:

Microsoft's CDN we're using for:

Our server:

  • Combined.js?v=2.2.0.6190 (Major.Minor.Iteration.Changeset)

Since part of our build process is combining and minifying all custom javascript, we do this via a custom script manager that includes the release or debug (non-minified) versions of these scripts depending on the build. Since Google doesn't host the jQuery validation package, this can be a down-side. MVC is including/using this in their 2.0 release, so you could rely completely on Microsoft's CDN for all your needs, and all of it automatic via the ScriptManager.

The only other argument to be made would be DNS times, there is a cost to this in terms of page load speed. On Average: Simply because it's used more (it's been around longer) ajax.googleapis.com is likely to be returned by DNS sooner than ajax.microsoft.com, simply because the local DNS server was more likely to get a request for it (this is a first user in the area penalty). This is a very minor thing and should only be considered if performance is extremely important, down to the millisecond.
(Yes: I realize this point is contrary to my using both CDNs, but in our case the DNS time is far overshadowed by the wait time on the javascript/blocking that occurs)

Last, if you haven't looked at it, one of the best tools out there is Firebug, and some plug-ins for it: Page Speed and YSlow. If you use a CDN but your pages are requesting images every time because of no cache-headers, you're missing the low-hanging fruit. Firebug's Net panel can quickly give you a quick breakdown of your page load-time, and Page Speed/YSlow can offer some good suggestions to help.

Solution 2

You should absolutely use the Google CDN for jQuery (and this is coming from a Microsoft-centric developer).

It's simple statistics. Those who would consider using the MS CDN for jQuery will always be a minority. There are too many non-MS developers using jQuery who will use Google's and wouldn't consider using Microsoft's. Since one of the big wins with a public CDN is improved caching, splitting usage among multiple CDNs decreases the potential for that benefit.

Solution 3

Google will send you a jQuery version minified with their own software, this version is 6kb lighter than the standard minified version served by MS. Go for Google.

Solution 4

One minor thing to consider is that both companies offer slightly different "extra" libraries:

Depending on your needs, this may be relevant.

Solution 5

It should also be noted that as ajax.microsoft.com is a sub domain of microsoft.com requests send all microsoft.com cookies adding to the overall time it takes to get the file back.

Also, ajax.microsoft.com is using default IIS7 compression which is inferior to the standard compression that other web servers use.

http://ajax.microsoft.com/ajax/jquery/jquery-1.4.4.min.js - 33.4K

http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js - 26.5K

Also, as others have mentioned google CDN is way more popular which greatly increases the chance of a file being cached.

So I strongly recommend using google.

Share:
65,011

Related videos on Youtube

Vishal_Kotecha
Author by

Vishal_Kotecha

Updated on November 30, 2020

Comments

  • Vishal_Kotecha
    Vishal_Kotecha over 3 years

    Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now.

  • blowdart
    blowdart over 14 years
    Less likely to be blocked? I'd love to know how you came up with that idea. The MS network isn't MS's anyway, it's akamai's who have been doing load balanced servers for a lot longer than google has, which makes a nonsense of the "better fall-over system" as well. Really, if you're going to make claims like this some evidence would be nice.
  • Nick Craver
    Nick Craver over 14 years
    Some companies, and I've worked for a few, block *.microsoft.com outright as part of their blocking of windows update. Is this correct? No, does it happen? Yes. Example: ajax.microsoft.com/...it falls under the *.microsoft.com block and not under the www exception, it's blocked when a company chooses to block anything but www.microsoft.com. I didn't say it's very likely, I said it's more likely, as I've never seen google blocked but have seen the reverse.
  • blowdart
    blowdart over 14 years
    And I've seen google blocked to stop gmail at government sites. But as it's so rare, I would hardly attempt to use it as a justification in this case.
  • Nick Craver
    Nick Craver over 14 years
    Rather ignorant methods of blocking windows update aren't so rare, especially at smaller companies who can't/won't afford the expertise to do it correctly (even if it is trivial)...which is the reason for noting it.
  • Falkayn
    Falkayn over 14 years
    jQuery will never be defined unless you bring it into your page. Caching the .js file doe snot make it available to all the browser pages by default!
  • Wil
    Wil over 14 years
    This works :S Re read the script - if it isn't defined, it writes this and loads?
  • Admin
    Admin over 14 years
    I've never understood why people do "<scr" + "ipt ..."
  • SeanJA
    SeanJA over 14 years
    "Depending on the browser, the amount of other preceding javascript, and how well-formed the overall code is, this is done to prevent the parser from interpreting the <script> and </script> tags as executeable code rather than as a string to be written."
  • Matt
    Matt almost 14 years
    I've had problems with Google's CDN being blocked by companies who only allow domains they've specifically approved. They allowed *.google.com and *.microsoft.com, and added my client's site, but googleapis.com was unknown, so it was blocked. Many of these companies are still clinging to IE6 (over 33% of this site's traffic... ugh!), so even if they understood the reason for the CDN, that wouldn't mean they'd allow it. To play it safe, we decided to just host jQuery from our server.
  • mamu
    mamu almost 14 years
    if we keep thinking that way then only bigger will get to breath. Don't just use google because it's google and assume everyone is with them(no doubt most are with them). But let best win, compare result and go with them.
  • rlorenzo
    rlorenzo almost 14 years
    It's not an assumption. Sites in the Alexa top 200,000 using Google's CDN outnumber Microsoft's over 100:1. In terms of popularity for caching, the only point in favor of the MS jQuery CDN is that Microsoft.com uses it, which gives it a lot of exposure from that one reference alone (but not as much as the thousands of top sites referencing Google's).
  • Will Dean
    Will Dean over 13 years
    Since this was written, MS have added jQuery-UI to their CDN: asp.net/ajaxlibrary/cdn.ashx#Using_jQuery_UI_from_the_CDN_10
  • Will Dean
    Will Dean over 13 years
    Since this was written, MS have added jQuery-UI to their CDN: asp.net/ajaxlibrary/cdn.ashx#Using_jQuery_UI_from_the_CDN_10
  • Walden Leverich
    Walden Leverich over 13 years
    Unfortunately some browsers (IE6) won't delay the processing of that online script until after the src= script is loaded so this won't work as expected. Wish it would!
  • jensgram
    jensgram over 13 years
    The problem is that jQuery will never be defined unless you've actively loaded it. In your script the first branch will always get executed (unless you have another jQuery inclusion above), rendering the script superfluous.
  • Ruan Mendes
    Ruan Mendes over 13 years
    Another reason not to use cdn for intranet apps is the fact that your app now depends on an internet connection. Many clients of ours have machines that don't have internet access.
  • Nick Craver
    Nick Craver over 13 years
    @Juan - while true in some cases it's not in most. If my app requires an internet connection (and most web-apps do) then it's not a factor really, since the page with the script tags wouldn't be loading either :)
  • Ruan Mendes
    Ruan Mendes over 13 years
    @Nick: This may be your experience, I've been writing enterprise web applications for 11 years now and they're usually run from a server within a company and they communicate only with the originating server. My comment was meant to warn developers not to add a dependency to apps that don't already depend on an internet connection
  • Alek Davis
    Alek Davis over 13 years
    Here is another reason not to use CDN for intranet-only apps based on personal experience. Most likely your company allows outside access via a firewall/proxy server, so if a firewall/proxy server has issues (which does not happen often, but does happen) then your app will break. If you have local (intranet) CDN or deploy jQuery as part of your web app, your app will work even with firewall/proxy servers not working.
  • Armstrongest
    Armstrongest over 13 years
    So, your IE6 users experience a slightly slow experience. Good trade-off if you ask me. IE6 is on the decline... even in Corporate intranets.
  • Stephen Kennedy
    Stephen Kennedy about 13 years
    This was a good objection at the time, but no longer applies as the recommended CDN domain name is now ajax.aspnetcdn.com. The blocking of *.microsoft.com objection also no longer applies.
  • Drew Freyling
    Drew Freyling about 13 years
    Google also don't host jquery vsdoc files either.
  • Alistair
    Alistair almost 13 years
    this is true. glad they finally fixed this part of it. Now I don't feel so bad about including jquery validate / cycle plugin from the ms cdn.
  • null
    null almost 12 years
    a little bit off topic maybe, but interesting point.
  • snumpy
    snumpy about 11 years
    @DaveWard, can you verify this is still the case, or have the tables turned somewhat over the last few years?
  • rlorenzo
    rlorenzo about 11 years
    @snumpy: The Google CDN has stretched its lead quite a bit from what I've seen. There's nothing wrong with the Microsoft CDN. It's fast and has a few files that the Google one doesn't. The cross-site caching benefit is dependent on net-wide coverage though, and Google's dominates all others in that regard.
  • Sachin Joseph
    Sachin Joseph almost 11 years
    @Nick Microsoft has moved it's CDN from ajax.microsoft.com to ajax.aspnetcdn.com. So there's no chance of blocking Microsoft's CDN as a part of blocking Windows Updates.
  • João dos Reis
    João dos Reis over 10 years
    Because I've switched from jQuery CDN to Microeoft's for hosting jQuery Mobile, I moved my other jQuery downloads to it from Google to reduce the number of DNS roundtrips. Just another factor :)
  • João dos Reis
    João dos Reis over 10 years
    Cookies thing also no longer applies because of switch to aspnetcdn.
  • Nathan Hornby
    Nathan Hornby over 10 years
    Is there a point where SO threads should be closed or marked for an update? I just got here through Google and this information is (naturally) horribly out of date and not as useful as it was back in '09 (!)
  • Fiona - myaccessible.website
    Fiona - myaccessible.website about 10 years
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
  • Amax
    Amax about 10 years
    To Fiona, it is my answer to the question. The question is "does it matter", my answer is "it depends on where his target audience is located", and I provided a site to test speed from different places around the world to let him decide which CDN to use. It is not a comment, it's an answer.
  • Dan Diplo
    Dan Diplo over 4 years
    Yet hostingcrown.com/jquery-cdn list Microsoft as No.1 having the fastest response time...