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
Explain url paremeter of jquery ajax method?
How do you check or uncheck a checkbox input or radio button?
What is difference between .setinterval() and .delay() ?
What does jQuery data() function do?
Can you please explain the difference between body onload() and document.ready() function? : jquery mobile
What is the use of delay() method in JQuery?
How do I check if the DOM is ready?
What is the use of param() method?
What is the between $(this) and 'this' in jquery?
Where jquery mobile works? : jquery mobile
What is a use of jquery filter?
What are the features of jquery used in web applications?
How to check variable is empty or not in jquery?
Explain the use of jquery .each() function? : jquery mobile
How did you become the creator of jquery ui? Whats the story behind that?