37

I want to use Google CDN for jQuery and jQuery UI..

I'm using the answer from here for jQuery. Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail

but i don't understand this bit:

if (typeof jQuery == 'undefined')

so how can i do it for jQuery UI? also, will this work with custom jQuery UI theme as this produces a custom js file too?

Community
  • 1
  • 1
raklos
  • 28,027
  • 60
  • 183
  • 301

3 Answers3

54

You can make the call using

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" /> 
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>

You can also link to other Ui themes by changes the name of the theme. In This case change the name base to any other theme name /base/jquery-ui.css to any other theme.

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />

Check out the jQuery UI Blog for a link of all CDN links http://blog.jqueryui.com/

If you're concerned that the Google CDN ever fails or goes down, you can fall back to a local copy when the CDN is offline (this example is baked into templates like HTML5 Boilerplate):

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
    window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"></script>')
</script>
gion_13
  • 41,171
  • 10
  • 96
  • 108
Hussein
  • 42,480
  • 25
  • 113
  • 143
  • You can also get your jQuery from Microsofts CDN. See the jQuery blog link above to access the links. Also Read 3 reason why you should get your jQuery from Google and not local host http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/ – Hussein Mar 05 '11 at 20:52
10

If you are having a custom jQuery UI theme, you have to host that on your own server. Google only hosts the main jQuery UI themes.

If you want to check whether or not the jQuery UI library has loaded, you can do this:

if (jQuery.ui) {
}
JasCav
  • 34,458
  • 20
  • 113
  • 170
0

Here is the list, just change to the version you need.

https://developers.google.com/speed/libraries/devguide#jquery-ui

Syed Priom
  • 1,893
  • 1
  • 21
  • 22