Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to load jQuery locally when CDN fails?

Answer Posted / chaitanya

It is a good approach to always use CDN but sometimes what if the CDN is down (rare possibility though) but you never know in this world as anything can happen.

Below given jQuery code checks whether jQuery is loaded from Google CDN or not, if not then it references the jQuery.js file from your folder.

Hide Copy Code

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

<script type="text/javascript">

if (typeof jQuery == 'undefined')

{

document.write(unescape("%3Cscript src='Scripts/jquery.1.9.1.min.js' type='text/javascript'%3E%3C/script%3E"));

}

</script>

It first loads the jQuery from Google CDN and then check the jQuery object. If jQuery is not loaded successfully then it will references the jQuery.js file from hard drive location. In this example, the jQuery.js is loaded from Scripts folder.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we have multiple document.ready() function on the same page? : jquery mobile

774


Write a code for the implementation of a module pattern.

826


What the use of $ symbol in jquery.

807


How to select combobox select value and text using jquery?

808


Explain cdn? : jquery mobile

802


Which version of jquery file should be used?

906


How can you delay document.ready until a variable is set?

807


Tell me is jquery a w3c standard? : jquery mobile

782


Why html 5 inputs look different across devices and browsers? : jquery mobile

794


Explain various methods to make ajax request in jquery? : jquery mobile

803


What were the biggest challenges of getting the jQuery 1.7 release ?

938


How do I check if the DOM is ready?

852


What is the advantage of using the minified version of jquery rather than using the conventional one?

857


What are the differences between size and length in jquery?

827


When can jquery be used?

832