jump to navigation

Fallback for CDN hosted jQuery December 3, 2011

Posted 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>



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s