Grab jQuery library from Google's CDN if failed then pull local version


/ Published in: JavaScript

Grab jQuery library from Google's CDN this way its faster, burns Google's bandwidth and not yours. Also users will have this cached if other sites are using it as well.

Downside of course is Google's servers do go down. This script will check if its available on Google's servers otherwise fall back to your local version.


Copy this code and paste it in your HTML
  1. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  2. <script>window.jQuery || document.write('<script src="js/libs/jquery-1.6.2.min.js"><\/script>')</script>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.