Fallback for CDN hosted jQuery December 3, 2011Posted by Tournas Dimitrios in JQuery.
Several big companies offer copies of jQuery hosted on their CDN’s (Content Delivery Network). Most notoriously Google , Microsoft but also jQuery themselves . Many developers believe (myself included ) that downloading JQuery-libraries from these Delivery Networks — instead from our webserver — saves bandwidth , downloads faster, and perhaps even stays cached jumping between different sites that use the same script . Although I would bed that Google’s CDN are the most reliable providers , it’s always wise to have a ” fallback ” recourse for our libraries . So the best solution is to use both links for our JQuery libraries . Use the CDN first , and if it fails , load the local copy . Here is a technique :
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="jquery.min.js; ?>"><\/script>')</script> .