How do i load the following in cdn and if they fail i would wnat my local file to load if this fails
this is how guys from html5boilerplate.com do this
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.5.1.min.js">\x3C/script>')</script>
You can check whether the jquery object exists after including the file so you have a failsafe (very rare)
<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")); //local
}
</script>
So, for the links you asked for
MS validate.js - http://ajax.microsoft.com/ajax/jQuery.Validate/1.6/jQuery.Validate.min.js
Google jquery.min.js - http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js
Google jquery.ui.js - http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js
Have a look at this question : Microsoft CDN for jQuery or Google CDN? They talk about your problem as well
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
jQuery: https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
jQueryUI: https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js
for more info. http://code.google.com/apis/libraries/devguide.html#jquery
for fallback something like this.
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
document.write(unescape("%3Cscript src='/path/to/your/jquery' type='text/javascript'%3E%3C/script%3E"));
}
if (typeof jQuery.ui == 'undefined')
{
// UI Not loaded
document.write(unescape("%3Cscript src='/jquery.ui.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
Check this to check if jquery has loaded or not.
For loading jQuery this will certainly help you.
Also you can check if validate plugin is loaded or not on here.
Already answered a similar questions at jquery ui - how to use google CDN
You can make the call using
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
You can also load jQuery from Microsoft CDN at
<script src=" http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js" type="text/javascript"></script>
You can also link to other Ui themes by changes the name of the theme. In This case change the name base to any other theme name /base/jquery-ui.css
to any other theme.
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />
Check out the jQuery UI Blog for a link of all CDN links http://blog.jqueryui.com/
If you want to revert back to your host in case Google failed, you can do
<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='/jquery.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
fOR jQUERY
<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")); //local
}
</script>
For Jquery Ui
if (jQuery.ui) {
document.write(unescape("%3Cscript src='/scripts/jqueryui-1.8.2.min.js' type='text/javascript'%3E%3C/script%3E")); //local
}
For Jquery validate
if(!jQuery().validate) {
document.write(unescape("%3Cscript src='/scripts/jquery.validate.min.js' type='text/javascript'%3E%3C/script%3E")); //local
}
Links MS validate.js - http://ajax.microsoft.com/ajax/jQuery.Validate/1.6/jQuery.Validate.min.js
Google jquery.min.js - http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js
Google jquery.ui.js - http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js
Google JqueryUi theme- (change base to one of the core theme name) http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With