I have read in several places how to fallback on a local copy of the jQuery library should the link hosted by either google or microsoft or other fail.
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
document.write(unescape("%3Cscript src='/Scripts/jquery-1.3.2.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
My application works within an intranet environment however and occasionally the external jQuery link doesn't so much fail but takes a long time to load (due to external internet connection issues).
I'm wondering if there is a way to not only use such a fallback but set a timeout for the CDN link so that if the link takes a certain amount of time it should fail and call on the fallback.
Something like:
if(timetoloadjquery > n) {
Use fallback local jQuery library.
}
Perhaps some kind of loop that checks if the jQuery is defined and if after so many iterations it is not....do something else?
Thanks for the help.
This may help you. After 5-seconds have passed, Javascript checks if jQuery is available, if not, then loads the library from local server.
1. With a timer
2. This one doesn't have a timer, it loads a local version if the CDN version fails.