我计划使用谷歌来下载UI和核心的jQuery库。我的问题是,他们是否允许我下载CSS,还是我必须自己托管它?

另外,如果我使用谷歌加载我应该如何加载其他插件?我可以压缩所有的插件在一起,还是应该是它自己的单独文件?


我想是的。为什么不呢?如果不提供CSS来支持脚本文件,就不是一个CDN

这种联系表明它们是:

我们发现特别令人兴奋的是 jQuery UI CSS主题现在 托管在谷歌的Ajax Libraries CDN上。

谷歌AJAX Libraries API,包括jQuery UI(目前v1.10.3),也包括流行的主题,根据jQuery UI博客:

谷歌Ajax Libraries API (CDN)

Uncompressed: http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.js Compressed: http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js Themes Uncompressed: black-tie, blitzer, cupertino, dark-hive, dot-luv, eggplant, excite-bike, flick, hot-sneaks, humanity, le-frog, mint-choc, overcast,pepper-grinder, redmond, smoothness, south-street, start, sunny, swanky-purse, trontastic, ui-darkness, ui-lightness, and vader. Themes Compressed: black-tie, blitzer, cupertino, dark-hive, dot-luv, eggplant, excite-bike, flick, hot-sneaks, humanity, le-frog, mint-choc, overcast,pepper-grinder, redmond, smoothness, south-street, start, sunny, swanky-purse, trontastic, ui-darkness, ui-lightness, and vader.

谷歌是托管jQueryUI css在这个链接https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css

如果你直接看这段代码,它正在使用@import导入css,这可能会很慢。您可能希望将导入分解到各个部分中,以获得轻微的性能优势:

https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.base.css https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.theme.css

jQuery现在有一个CDN访问:

code.jquery.com/ui/[版本]/主题/[主题名称]/jquery-ui.css


为了让这更简单一点,给你:

base: http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css black-tie: http://code.jquery.com/ui/1.9.1/themes/black-tie/jquery-ui.css blitzer: http://code.jquery.com/ui/1.9.1/themes/blitzer/jquery-ui.css cupertino: http://code.jquery.com/ui/1.9.1/themes/cupertino/jquery-ui.css dark-hive: http://code.jquery.com/ui/1.9.1/themes/dark-hive/jquery-ui.css dot-luv: http://code.jquery.com/ui/1.9.1/themes/dot-luv/jquery-ui.css eggplant: http://code.jquery.com/ui/1.9.1/themes/eggplant/jquery-ui.css excite-bike: http://code.jquery.com/ui/1.9.1/themes/excite-bike/jquery-ui.css flick: http://code.jquery.com/ui/1.9.1/themes/flick/jquery-ui.css hot-sneaks: http://code.jquery.com/ui/1.9.1/themes/hot-sneaks/jquery-ui.css humanity: http://code.jquery.com/ui/1.9.1/themes/humanity/jquery-ui.css le-frog: http://code.jquery.com/ui/1.9.1/themes/le-frog/jquery-ui.css mint-choc: http://code.jquery.com/ui/1.9.1/themes/mint-choc/jquery-ui.css overcast: http://code.jquery.com/ui/1.9.1/themes/overcast/jquery-ui.css pepper-grinder: http://code.jquery.com/ui/1.9.1/themes/pepper-grinder/jquery-ui.css redmond: http://code.jquery.com/ui/1.9.1/themes/redmond/jquery-ui.css smoothness: http://code.jquery.com/ui/1.9.1/themes/smoothness/jquery-ui.css south-street: http://code.jquery.com/ui/1.9.1/themes/south-street/jquery-ui.css start: http://code.jquery.com/ui/1.9.1/themes/start/jquery-ui.css sunny: http://code.jquery.com/ui/1.9.1/themes/sunny/jquery-ui.css swanky-purse: http://code.jquery.com/ui/1.9.1/themes/swanky-purse/jquery-ui.css trontastic: http://code.jquery.com/ui/1.9.1/themes/trontastic/jquery-ui.css ui-darkness: http://code.jquery.com/ui/1.9.1/themes/ui-darkness/jquery-ui.css ui-lightness: http://code.jquery.com/ui/1.9.1/themes/ui-lightness/jquery-ui.css vader: http://code.jquery.com/ui/1.9.1/themes/vader/jquery-ui.css

如果你指的是jQuery UI css,你可以使用这个:

<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

正如奥巴马所说的“是的,我们可以”。这里是它的链接。developers.google.com/ # jquery

你需要使用

谷歌

ajax.googleapis.com/ajax/libs/jqueryui/[VERSION NO]/jquery-ui.min.js
ajax.googleapis.com/ajax/libs/jqueryui/[VERSION NO]/themes/[THEME NAME]/jquery-ui.min.css

jQuery CDN

code.jquery.com/ui/[VERSION NO]/jquery-ui.min.js
code.jquery.com/ui/[VERSION NO]/themes/[THEME NAME]/jquery-ui.min.css

微软

ajax.aspnetcdn.com/ajax/jquery.ui/[VERSION NO]/jquery-ui.min.js
ajax.aspnetcdn.com/ajax/jquery.ui/[VERSION NO]/themes/[THEME NAME]/jquery-ui.min.css

在图库子选项卡中找到主题名称http://jqueryui.com/themeroller/

.

但我不建议你从cdn主机,原因如下

虽然在谷歌CDN的情况下,与其他CDN相比,你的命中率很好,但它仍然非常低。(任何CDN,不仅仅是谷歌)。 通过cdn加载,你会有3个请求,一个用于jQuery.js,一个用于jQueryUI.js,一个用于你的代码。你可以把它压缩到本地,然后作为一个资源加载。

http://zoompf.com/blog/2010/01/should-you-use-javascript-library-cdns

jQuery UI < 1.13被谷歌Page Speed Insights认为是一个安全漏洞。

请使用安全修复的最新版本。到2022年,这将是1.13.2

Ex:

https://ajax.googleapis.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js https://ajax.googleapis.com/ajax/libs/jqueryui/1.13.2/themes/smoothness/jquery-ui.min.css

完整的HTML标签示例:

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.13.2/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js"></script>