Как мне загрузить следующее в cdn, и если они не удастся, я бы загрузил свой локальный файл, если это не удастся
- CDN Google: jquery.min.js и jquery-ui.min.js.
- CDN Microsoft: jQuery.Validate.min.js
Как мне загрузить следующее в cdn, и если они не удастся, я бы загрузил свой локальный файл, если это не удастся
вот как это делают ребята из html5boilerplate.com
<!-- 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>
Вы можете проверить, существует ли объект 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>
Итак, для ссылок, которые вы просили
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
Взгляните на этот вопрос: Microsoft CDN для jQuery или Google CDN? Они также говорят о вашей проблеме
<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
для получения дополнительной информации. http://code.google.com/apis/libraries/devguide.html#jquery
для запасного варианта что-то вроде этого.
<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>
Отметьте это, чтобы проверить, загрузился или нет.
Для загрузки jQuery это, безусловно, поможет вам.
Также вы можете проверить, загружен ли плагин валидации на здесь.
Уже ответил на аналогичные вопросы на jquery ui - как использовать google CDN
Вы можете позвонить, используя
<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>
Вы также можете загрузить jQuery из Microsoft CDN по адресу
<script src=" http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js" type="text/javascript"></script>
Вы также можете ссылаться на другие темы пользовательского интерфейса, изменив название темы. В этом случае измените базу имен на любую другую тему, имя /base/jquery-ui.css
на любую другую тему.
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />
Посетите блог jQuery UI, чтобы найти ссылку на все ссылки CDN http://blog.jqueryui.com/
Если вы хотите вернуться к своему хосту в случае сбоя Google, вы можете сделать
<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>
ДЛЯ 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>
Для 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
}
Для проверки JQuery
if(!jQuery().validate) {
document.write(unescape("%3Cscript src='/scripts/jquery.validate.min.js' type='text/javascript'%3E%3C/script%3E")); //local
}
Ссылки 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 - (измените базу на одно из основных названий темы) http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css