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 width() vs css(‘width’) in jquery
What is the use of queue() in jquery?
How We Can Write Code Specific To Browser In Jquery?
What is the difference between onload() and document.ready() function used in jquery?
What happen if you return false from a jQuery event handler?
what does $("div") will select? : jquery mobile
How to get the current offset of the first matched element, in pixels, relative to the document using ?
How can we apply css in last child of parent using jquery library?
What is jquery connect and how to use it?
Define jquery $.ajax() method?
How to stop jqm from auto-enhancing an element? : jquery mobile
What is the use of the animate() method in jquery?
Jumping off of jquery ui for a second, do you 'release early, release often' with all of your projects? What are your thoughts on that strategy?
Can you write a jquery code to select all links inside the paragraph?
Need to add jQuery file in both Master and Content page?