我应该让我的网页在我自己的服务器上还是从code.jquery.com引用jquery.js的副本? [英] Should I have my web pages reference a copy of jquery.js on my own server or from the code.jquery.com?

查看:78
本文介绍了我应该让我的网页在我自己的服务器上还是从code.jquery.com引用jquery.js的副本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的JavaScript等可能是这个愚蠢的问题。

我正在研究JQuery-UI教程,他们有:

I am new to javascript etc so may be this is dumb question.
I was looking into JQuery-UI tutorials and they have:

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>     
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />    
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>    
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

如果我可以包含这样的js代码,为什么我需要下载jquery库? / p>

If I can include js code like this, why would I ever need to download the jquery library?

推荐答案

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
if (!window.jQuery) {
    document.write('<script src="/path/to/your/jquery"><\/script>');
}
</script>

使用CDN时,用户不必再次下载jquery文件可能已经缓存了。

When you use a CDN, the users don't have to download the jquery file again as they most probably already have it cached.

第二个脚本标记中的代码检查jQuery是否可以从CDN获得,并返回到本地机器上的jquery副本。

The code in second script tag checks if the jquery was available from CDN or not, and falls back to local copy of jquery on your machine.

这篇关于我应该让我的网页在我自己的服务器上还是从code.jquery.com引用jquery.js的副本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆