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
How we can set the html contents of an element in jquery?
How method can be called inside code behind using jQuery?
What is event preventdefault () and event stoppropagation () in jquery?
How to debug jquery code/ debug jquery?
How can we apply css in odd childs of parent node using jquery library?
Where can we download JQuery?
Differentiate among .empty() vs .remove() vs .detach() in jquery.
How is the deferred method in jquery important in relation to animate method?
How can events be prevented from stopping to work after an ajax request?
what are the features of jquery
Explain the basic need to start with jquery? : jquery mobile
What is the difference between "#" and "." selector in JQuery?
Why are not some scripts and styles loading? : jquery mobile
How to validate email using jquery?
Can we include multiple version of jquery? : jquery mobile