来自 CDN 的 jquery

发布于 2024-10-26 05:06:03 字数 190 浏览 2 评论 0原文

我如何在 cdn 中加载以下内容,如果失败,我将需要加载本地文件(如果

  1. Google 的 CDN 失败):jquery.min.js 和 jquery-ui.min.js。
  2. 微软的 CDN: jQuery.Validate.min.js

How do i load the following in cdn and if they fail i would wnat my local file to load if this fails

  1. Google's CDN : jquery.min.js and jquery-ui.min.js.
  2. Microsoft's CDN : jQuery.Validate.min.js

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦屿孤独相伴 2024-11-02 05:06:03

这就是 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>

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>
小霸王臭丫头 2024-11-02 05:06:03

您可以在包含文件后检查 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

谷歌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 for jQuery 还是 Google CDN? 他们也讨论了您的问题

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

于我来说 2024-11-02 05:06:03
<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>
<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>
骄傲 2024-11-02 05:06:03

检查这个来检查jquery是否是否已加载。

对于加载 jQuery 肯定会对您有所帮助。

您还可以检查 此处

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.

﹉夏雨初晴づ 2024-11-02 05:06:03

已经在 jquery ui - how to use 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>

您还可以从 Microsoft CDN 加载 jQuery,

<script src=" http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js" type="text/javascript"></script>

您还可以通过更改主题名称来链接到其他 Ui 主题。在这种情况下,将名称 base 更改为任何其他主题名称 /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>

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>
浮萍、无处依 2024-11-02 05:06:03

对于

<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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文