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?



How to load jQuery locally when CDN fails?..

Answer / 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

More jQuery Interview Questions

Why we use chaining in jquery?

0 Answers  


What is the use of jquery .each() function?

1 Answers  


How to disable cut,copy and paste in TextBox using jQuery?

0 Answers  


How to check variable is empty or not in jquery?

0 Answers  


Can you write a code to select all links inside the paragraph?

0 Answers  


What is the difference between eq() and get() methods in jQuery?

1 Answers  


How can jquery library be added to pages? Write a basic jquery code?

0 Answers  


explain bind() vs live() vs delegate() methods in jquery

0 Answers  


How to resolve conflicts with other libraries?

0 Answers  


Is jQuery a W3C standard?

2 Answers  


How do I check if an element is hidden in jQuery?

0 Answers  


What are the selectors in jquery? How many types of selectors in jquery?

0 Answers  


Categories