0

I have a page that uses jQuery UI. Ideally I would like to use the google cached version if possible, but if that was unavailable I would like to fall back on a local version.

Is this possible? I have been hunting through the html <script> tag reference but cant find anything to do a check and fallback.

jmosbech
  • 1,128
  • 9
  • 8
CJH
  • 195
  • 3
  • 5
  • 16
  • possible duplicate of [Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail](http://stackoverflow.com/questions/1014203/best-way-to-use-googles-hosted-jquery-but-fall-back-to-my-hosted-library-on-go) – kleinfreund Jan 05 '14 at 14:40

2 Answers2

2

You can do something like this (while of course changing the URLs to suit your needs):

<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script>window.jQuery.ui || document.write('<script src="/libs/jquery-ui.js"><\/script>');</script>
jmosbech
  • 1,128
  • 9
  • 8
1

This was answered before: Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail

The same applies for jQueryUI ofcourse.

<script src="/path/to/external/jqueryui"></script>
<script>
if (!window.jQuery.ui) {
    document.write('<script src="/path/to/local/jqueryui"><\/script>');
}
</script>
Community
  • 1
  • 1
Gilly
  • 9,212
  • 5
  • 33
  • 36