Do you know about this undocumented Google CDN feature?
CSS, jQuery, UI By Dave Ward. Updated February 25, 2010By now, you probably already know that Google hosts jQuery on its AJAX APIs CDN, free of charge. As I’ve discussed here in the past, I’m a big fan of using their CDN to achieve decreased latency, increased parallelism, and better caching.
If you’ve explored the AJAX APIs documentation a bit, you may know that jQuery UI is also hosted on Google’s CDN. Unfortunately, since jQuery UI plugins depend on a ThemeRoller theme, using a CDN for jQuery UI isn’t as easy as with jQuery itself.
Or, is it?
My <head> is in the cloud
While poking around a couple months ago, I stumbled upon something that I’ve found extremely useful: An entire jQuery UI theme hosted on Google’s CDN!
Not only is the theme’s CSS stylesheet there, but all 14 of the theme’s images are hosted in the correct relative location too. That means you can apply the entire theme to a page with a single CSS reference and no local files.
Even better, while JavaScript and CSS includes are unable to take full advantage of the increased parallelism a CDN offers, the theme’s images do. This makes loading the theme from Google’s CDN particularly effective.
Using it
Using this on your own pages couldn’t be easier. There are no files to download, no paths to worry about, and no configuration is required. Just a reference to jQuery, jQuery UI, and the ThemeRoller theme you want to use will is all you need.
For example, if you wanted to build a quick demo of the jQuery UI Tabs plugin, use these references in the head of your page:
<!DOCTYPE html> <html> <head> <!-- To avoid horizontal scrolling in this code listing. --> <base href="http://ajax.googleapis.com/" /> <!-- Reference the theme's stylesheet on the Google CDN --> <link href="/ajax/libs/jqueryui/1.7.2/themes/start/jquery-ui.css" type="text/css" rel="Stylesheet" /> <!-- Reference jQuery and jQuery UI from the CDN. Remember that the order of these two elements is important --> <script src="/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script src="/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script> <!-- Initialize the tabs when the document is ready --> <script type="text/javascript"> $(document).ready(function() { // See the jQuery UI Tabs documentation for // more information about how this works. $('#tabs').tabs(); }); </script> </head>
Note: You shouldn’t use the <base> tag like this in your pages. It affects all links on the page, not just those in the <head>. I’m just using it here to avoid horizontal scrolling (the bane of my existence when posting code here).
Then, just a bit of corresponding markup in the body of the document (see the jQuery UI Tabs documentation for specifics):
<body> <div id="tabs"> <ul> <li><a href="#tab-1">Tab 1</a></li> <li><a href="#tab-2">Tab 2</a></li> <li><a href="#tab-3">Tab 3</a></li> </ul> <div id="tab-1"> <p>These tabs were created with JavaScript, CSS, and images hosted on Google's AJAX APIs CDN.</p> <p>Thanks, Google!</p> </div> <div id="tab-2"> <!-- Tab 2's content goes here. --> </div> <div id="tab-3"> <!-- Tab 3's content goes here. --> </div> </div> </body> </html>
That HTML (without a single file or image hosted locally) results in this:

Don’t like the theme in my example? Don’t worry, because all 24 of the standard ThemeRoller presets are also hosted on the CDN. See the end of this post for a full listing.
Nothing’s perfect
There are a couple of potential issues when using these CDN hosted themes.
First, these themes aren’t minified. Minification shaves about 20% off the size of an average ThemeRoller theme’s CSS, which is definitely worthwhile. Hopefully, minified versions will be available at some point (assuming I didn’t miss ones that may already be hiding there somewhere). In the meantime, Google does properly gzip compress them though, which makes the difference less significant.
Second, if you normally customize ThemeRoller’s CSS or images manually, this probably isn’t for you. Lacking control over the base CSS style is something that you can work around, but isn’t worth the complexity and extra HTTP requests.
However, you can still reference the CDN’s images from custom CSS, by using absolute paths.
Conclusion
Overall, this seemingly small feature has been surprisingly useful in my day-to-day development. While it’s technically not very difficult to download and set up local ThemeRoller themes, there’s more friction to it than I care for. Boiling the entire process down to a single CSS reference removes all of that friction.
Even if you don’t like the idea of relying on a CDN hosted theme for production sites, this is great for prototyping. Anything that makes prototyping faster is a big win, because it allows you to try more ideas in the same amount of time.
What do you think? Does this sound useful to you? Are you comfortable leaning on Google’s CDN for your entire jQuery UI theme? Would you use this in production?
Full Theme Listing
The URLs below reference jQuery UI v1.7.2 themes. If 1.7.2 isn’t the latest version at the time that you’re reading this, you should be able to replace 1.7.2 in the URL with the current version and find a current theme hosted on the CDN.
Click any of the thumbnails to view that theme on ThemeRoller.
Click any of the input fields to select the full URL to the theme’s CDN hosted CSS file, ready for copy/pasting into your page.
Similar posts
What do you think?
I appreciate all of your comments, but please try to stay on topic. If you have a question unrelated to this post, I recommend posting on the ASP.NET forums or Stack Overflow instead.
If you're replying to another comment, use the threading feature by clicking "Reply to this comment" before submitting your own.
10 Mentions Elsewhere
- DotNetShoutout
- DotNetBurner - jQuery
- » Twitter alerts: using twitter streaming API for fun and profit Corunet. El Blog
- ASP.NET GridView – edit records using JQuery Dialog « RAD for N-Tier web apps in .NET
- uberVU - social comments
- 3 reasons why you should let Google host jQuery for you
- The Official jQuery Podcast
- The Official jQuery Podcast – Episode 32 – Dave Ward
- jQueryUI a Microsoft CDN-en « Balássy György szakmai blogja
- jQuery UI Component Library released by Component One | Devpit



Great, that is what I looks for.
Hi, this is a great feature which I have used for a long time on our corporate websites.
A note of caution, the only downside is you can’t run a website utilising Jquery locally without an internet connection..
Cheers,
Mark
Microsoft also have a CDN on Beta, try checking any news on here:
http://weblogs.asp.net/scottgu/archive/2009/09/15/announcing-the-microsoft-ajax-cdn.aspx
What do you think of the Microsoft AJAX CDN?
I think it’s great for hosting the ASP.NET AJAX files.
I’d recommend against using it for jQuery though.
Hey Dave,
I’ve lamented that this is not better documented.. But now that you’ve done a fantastic job of that, I was wondering:
Would you be willing to change the post title to something a bit more googleable? Maybe like `The jQuery UI themes are hosted on the Google CDN!`
With that change you’d be helping a LOT more people with this info. Thx!
I definitely may do that if it doesn’t seem to get traction or does poorly organically. I sometimes use these silly “viral” titles to catch attention for topics that you might not ever think to search for if you didn’t already know about them.
I think Microsofts CDN is great. I’ts even faster then Google’s…Hopefully there will be the jQuery UI too!
As far as I know, both their CDNs are facilitated by Akamai. Neither is significantly “faster” than the other.
Hi Dave,
If that is the case, why would recommend against using Ms CDN for jQuery?
Because it reduces the chances that your user will get a 304 for jQuery when first hitting your site and removes the benefit of them also getting a 304 on the next site they visit using the Google CDN. Everyone’s better off if we just use one CDN for each library.
Dave,
Also with the MS CDN, since it is on a microsoft.com domain all cookies will be sent with each request to the CDN. Not necessarily bad, but I would of preferred a separate domain like Google did with their CDN.
This is AWESOME! Thanks for the heads up. You are right this will work well for jQuery UI demos.
Great post !
(the link for Dark Hive should read:
http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/dark-hive/jquery-ui.css)
You’re right. I just updated it. Thanks for letting me know about that.
Thanks Dave! I first heard about you on the Polymorphic Podcast and I am now a believer and follower! :-)
Following your articles, I’ve updated our code to no longer to start using the Google CDN. Per this article, I’m also going to use the google CDN themes.
As a fallback, I’m checking to see if jquery === ‘undefined’ and including my local scripts and css if I can’t connect to the cdn.
Thanks for sharing!
Nathan
Wow, excellent find, thanks for the share.
Even Microsoft has it now. Not sure about the themes but at least the main JQuery file.
Any idea how I would just load a particular widget and not the whole jQuery UI js?
Like if I just needed the datepicker and not the whole thing?
Right now I can import ui.datepicker.js from my locally hosted jQuery UI. I’d like to be able to do the same thing with the Google jQuery UI CDN.
Unfortunately, there aren’t any custom bundles hosted on the CDN (as far as I know). Keep an eye out for the new jQuery plugins CDN though, which I believe is supposed to support custom combined bundles.
It is worth noting that the entire jQuery UI 1.7.2 package is only 45k when minified and gzipped. If you find yourself using even one or two more jQuery UI widgets, it would probably make sense to go ahead and reference the full version off the CDN.
Will jQuery plugins CDN be hosted on Google too?
I’m not sure where they’ll be hosted. I’d guess not on Google’s CDN, for the sake of flexibility.
Where did you hear for this? I thought you have some more (insider) information.
If it’s not on Google, we will have three hosters of jQuery which removes usefulness of caching.
If the plugins are hosted on a separate CDN, that wouldn’t lessen the benefit of using the Google CDN for jQuery itself.
That is true. I hope that they’ll not create another mirror for jQuery and jQuery UI. First thought I got after reading your previous comment is that there will be another hoster for jQuery too, not just plugins, but now after new reading I see that you didn’t say that.
Google won’t add a lot, if any, additional plugins to their CDN. In that case a jQuery CDN makes sense.
Thanks for documenting this. So far the URLs were in the 1.7.2 release blog post, but nowhere else. We really need to add them to the jQuery UI site.
This is a really helpful feature – thanks for bringing it to light.
Just throwing this out for discussion. I’ve been using code to access the Google hosted jQuery library for a while now. One of my favorite plugins to use with jQuery is the “Form” plugin. My question is, can I use similar code to access the file on github or google? For example I could use this code:
<script type="text/javascript" src="http://github.com/malsup/form/raw/master/jquery.form.js"></script>This works, I just want to know if it’s OK to use this technique or is it not “kosher” or frowned upon? It would be nice to leverage google (and/or github etc) to use their hosted libraries. Are these not cached when accessed this way? Pros and Cons…
I don’t know what github’s stance specifically, but it’s considered bad form unless explicitly condoned.
Most repositories aren’t optimized for serving end users anyway. For example, github doesn’t serve that with a far future expires header. Assuming you optimize for end user consumption, hosting it yourself would be better than using github’s copy, even if github is faster.
I have been using this feature for quite a while, and all of a sudden it broke when jqueryui released 1.7.2 themes for me. Of note is the fact that I tend to use the version-ing shorthand when using the google cdn. Instead of 1.7.2 in the url I use 1, which gets me the latest version of the major 1. So my link used to look like this:
For some reason the cdn starting returning a 404 for this url, and it wasn’t until I added the minor that it would return:
All of the other urls still work fine using just the minor.
Just posting this in case any of your other readers ran into this issue. Btw, love the blog.
One thing to keep in mind is that anything less specific than x.y.z will only send the file back with a +1 hour expires header. In other words, 1, 1.7, and 1.8 send the files back only to be cached for an hour, while 1.7.2 and 1.8.0 send them back with a +1 year expires header.
So, it’s probably best to use 1.7.2 instead of 1.7 in your case.
Interesting Dave, I did not know that. That is too bad, I really like the flexibility of just using the major in the url. One hour is not nearly long enough.
While I do not believe a cached file would survive a year on anyone’s computer with the browser doing FIFO caching I agree that the longer the cache time is preferable.
If google’s cdn would put an expire header of 24 hours or more on the 1.7 version then I might possibly accept that.
Because the expires header precludes even checking for a 304, it makes sense that they can’t put a long expires header on the less specific versions. Otherwise, you wouldn’t be able to predict which version your users would be seeing when a new version was released (until the expires duration had elapsed).
Is there a tool to test the speed difference of using code between a particular CDN i.e Google VS Microsoft, against local serving of the script files?
You can use Firebug’s “net” tab to test the difference from your own location.
To test from an outside location, you can use a tool like Pingdom’s: http://tools.pingdom.com/
This technique also works with https, which is great for my e-comm sites.
Kewl!
I like that kind of stuff very much. Especially for the admin panel of the CMS we’re crafting, so it could shrink (each bit spared is a victory!) the bandwidth usage of our clients :).
I wish they could provide a min version but hey, nothing’s perfect!
Anyway, thanks for the share! I’ll follow your blog from now.
thanks, exactly what I searched. Would’ve flattr that.
Just a note, if you don’t want to specify the specific version (latest is 1.8.5), the CSS urls respect the same versioning as the .js files.
For instance, you can load jquery from google by specifying version 1.8.5, 1.8, or just 1.
So in the same method, you can specify whichever matching specific or non-specific version for your CSS, such as:
http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/ui-lightness/jquery-ui.css
http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/ui-lightness/jquery-ui.css
http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css
Kudos on this good find regarding the hosted themes, that’s very helpful :-)
Cheers
You should avoid using the “latest version” URLs, because they have significantly shorter expires headers than the fully specific URL (i.e. 1.8.5).
Good point to consider :-)
Now if they only would enroll the number of themes, it would be great. Or create new themes (ie in google webmaster central). That would really be perfect CDN solution. Thank you for the great info.
That is extremely helpful. Thank you.
nteresting Dave, I did not know that. That is too bad, I really like the flexibility of just using the major in the url. One hour is not nearly long enough.
Mark,
You can run a website with jQuery on an intranet with no internet connection – there’s nothing stopping you from hosting the jQuery files locally (you don’t have to use the CDN if you don’t have an internet connection)
Cheers,
Michael
Hi,
Thanks for this plus your other post:
http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/
Just saved me a ton of time and I learnt quite a bit – especially useful the tip about leveraging jquery on google.
thanks
Thanks, this is precisely what I was trying to find.
Thanks for the great info!!!
Thanks for this post. New to jQuery and the list of calendars with embedded theme names made quick work for me.
I’m back again to grab a few theme URLs. Again, thank you for posting this and making it so easy to get at them.