None

Use a CDN for jQuery with Fallback

January 22, 2010

This is a cracking idea (found at http://weblogs.asp.net/jgalloway/archive/2010/01/21/using-cdn-hosted-jquery-with-a-local-fall-back-copy.aspx).

You should be using a Content Delivery Network for jQuery and other JavaScript libraries. If lots of sites do this then the library may already be in your browser cache and can be just used without a download.

But what happens if the CDN is down? Here's a technique for falling back to a locally hosted copy in that case:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
  if (typeof jQuery == 'undefined')
  {
    document.write(unescape("%3Cscript src='/site_media/jquery-1.3.2.min.js' type='text/javascript'%3E%3C/script%3E"));
  }
</script>

Tags: jquery cdn google