Google Hosting YUI Files on ajax.googleapis.com

By Eric MiragliaNovember 19th, 2008

Update: It should be added that Google’s CDN provides SSL support whereas Yahoo’s does not. If you were previously hosting your own set of YUI files to use in a secure environment, the Google CDN may be a way to offload that bandwidth and improve performance.

Google has been hosting some of the popular AJAX libraries for awhile, and we’re pleased to announce that YUI has now been added to that roster. Now, you can choose between yui.yahooapis.com and ajax.googleapis.com when you evaluate your hosting options for YUI files. We’ve added Google as an option in the CDN section of the Dependency Configurator; it’s easy to configure your implementation and switch the generated URLs from one source to the other.

There are two things to keep in mind in working with the Google CDN, particularly if you’re currently using Yahoo’s CDN:

  1. Combo-handling: Combo-handling (the on-the-fly aggregation of files to reduce HTTP requests) is supported on Yahoo’s CDN but not on Google’s;
  2. Versions: Google’s CDN contains the current version of YUI (2.6.0) and will get future versions as they become available; legacy versions of YUI are not available from the Google CDN.

If you’re using YUI Loader to bring in your YUI files, it’s a simple thing to switch to Google’s servers using YUI Loader’s base configuration option. Here’s what you would do to pull the YUI DataTable and its dependencies from the Google CDN using YUI Loader:

<!--Include YUI Loader: --> 
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/yui/2.6.0/build/yuiloader/yuiloader-min.js">
</script> 

<!--Use YUI Loader to bring in your other dependencies: --> 
<script type="text/javascript"> 
// Instantiate and configure YUI Loader: 
(function() { 
var loader = new YAHOO.util.YUILoader({ 
        base: "http://ajax.googleapis.com/ajax/libs/yui/2.6.0/build/", 
        require: ["datatable"], 
        onSuccess: function() { 
            //instantiate your DataTable here...
    } 
}); 

// Load the files using the insert() method. 
loader.insert(); 
})(); 
</script>

The Dependency Configurator will generate this script for you; simply load this configuration and switch to the “Dynamic Loading with YUI Loader” tab.

Thanks to Vadim Spivak at Google and Dion Almaer (now at Mozilla) for helping to make this additional option available to the YUI developer community. We love that Google is supporting web developers in this way — grabbing YUI files from Google’s global infrastructure is a fantastic option to have.

12 Comments

  1. I’m curious now which is a faster option. I’m not a fan of the combo handling because chances are uses won’t have a cache of a resource at a dynamically-generated URL always. I think more can be done with the combo handling to make it more effective from a caching perspective.

    It would be interesting to see someone run some tests against the two CDN options…

  2. My tests both show they are about the same from my house (on comcast)… ~380ms. Probably depends on where your user is accessing your site from. They were both 60ms ping times for me.

    Sam

  3. @Eric,

    To add to what Sam observed, here is the result of a simple test with ten iterations loading the JS requirements for DataTable — four files without combo handling, 1 file with combo handling, empty cache:

    Yahoo CDN individual files: 585.4ms
    Yahoo CDN combo handled file: 401.2ms
    Google CDN individual files: 1007.1ms

    I used FF3, Mac OSX, running on a DSL line in the Bay Area. My guess is that, around the world, you’d see a lot of variation; however, I would expect that you’d always see the combo-handled file outperform the individual files.

    Regards,
    Eric

  4. Although I do see YUI hosted at the location mentioned, it is not listed on the site as a library currently hosted there (see http://code.google.com/apis/ajaxlibs/documentation/)… not even a blog entry on their blog (see http://googleajaxsearchapi.blogspot.com/).

  5. @bws — The Google team just got the files loaded, and they’re in the process of updating the documentation. You’ll see that and their blog post soon. -Eric

  6. Are the YUI3 files hosted there too yet? What would the url be?

  7. @Andrew — No, we haven’t submitted YUI3 to Google for hosting yet. Once we get out of preview mode we’ll work on getting YUI3 up there as well as YUI2. Keep in mind that the granularity of the modules and submodules in YUI3 make combo-handling a matter of some importance when it comes to performance, and Google does not support combohandling on its Ajax library CDN yet — so the Yahoo CDN may be significantly more performant for YUI3. -Eric

  8. Google is more global (has more hardware around the world) then US-centric Yahoo, so I guess it’s better to use Google CDN for global websites and Yahoo one for US. Am I right?

  9. @Kamil T. — My guess is that in most of the world you’ll be better off using combo-handled files from the Yahoo servers than individual files from the Google servers. I provided some urls in the comments above with a rudimentary way to test this in your own locale, but it’s a crude test. I do think there are parts of the world where Google will outperform Yahoo and vice versa. Regards, Eric

  10. Thanks for the information!

    It’s interesting google offers https, while yahoo does not.

  11. @Harvey:

    Good to know. Might not be the best idea in an HTTPS environment to use externally hosted code. This does give a points towards using Google over Yahoo for CDN.

  12. I live in Poland (Warsaw) and I have good DSL connection from our biggest internet provider TP SA. My ping’s for Yahoo are 160ms. Traceroute shows me that files are in UK, but packets was sended through US! This is the list of cities: Warsaw, New York, Ashburn, Dallas, London. For Google ping is 50ms and they are delivered directly from Germany (maybe from Frankrurt Am Main). For development purposes I choose Google. For site it’s still better to have minimized copy on own server.