Posted By

jeremytarpley on 05/25/11


Tagged


Versions (?)

Smart way to add jquery or other js from Google's cdn - fail over to local copy


 / Published in: JavaScript
 

if the Google cdn copy of jquery or what ever fails, use a local copy of the script

  1. <!-- Grab Google CDN's jQuery. fall back to local if necessary -->
  2. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
  3. <script type="text/javascript">!window.jQuery && document.write('<script src="http://www.thiswebsitesdomain/js/jquery.js"><\/script>')</script>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: mecha on May 27, 2011

you should credit the original author.

Posted By: jeremytarpley on July 12, 2011

@mecha, you are absolutely right - sorry about that, I'll try to track down where I found it.

I'm a complete hack, anything I've put on this site that looks remotely intelligent is probably not mine!

Posted By: jeremytarpley on July 12, 2011

Can't remember where I first found this or who originally created this technique but I've found a few others who are using it that reference Paul Irish's excellent html5 boilerplate. http://html5boilerplate.com/

You need to login to post a comment.