top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to load jQuery locally when CDN fails?

+3 votes
493 views
How to load jQuery locally when CDN fails?
posted Jun 5, 2014 by Merry

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

Try the following steps
1. Load the jQuery from your CDN.
2. Check the jQuery object, if jQuery is not loaded then it load the jQuery.js from your server.

Check this example (source: http://www.jquerybyexample.net/2011/04/how-to-load-jquery-locally-when-cdn.html)

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
  document.write(unescape("%3Cscript src='Scripts/jquery.1.5.1.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
answer Jun 5, 2014 by Salil Agrawal
Similar Questions
+2 votes

Can someone help me with this (Better to provide code for top 3 providers Google, Microsoft and JquerySite).

...