Google CDN Jquery 加载不工作

发布于 2024-11-17 13:45:10 字数 975 浏览 3 评论 0原文

目前,我的一个布局中有一组丑陋的单独的 javascript 文件,我正在尝试使用 Google CDN 清理它。

当前状态(我知道很糟糕):

...css...  
<%= yield :head %>

<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" %>
<script type="text/javascript" src="http://cdn.jquerytools.org/1.2.5/all/jquery.tools.min.js"></script>
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js" %>
<%= javascript_include_tag "ui/jquery.ui.core", "ui/jquery.effects.core",
   "ui/jquery.effects.highlight", "ui/jquery.ui.widget", "ui/jquery.ui.tabs",
   "ui/jquery.ui.progressbar" %>
<%= javascript_include_tag "jquery.ui.stars.min", "application", "rails" %>

我尝试将底部标签中的第二个(带有一长串文件)替换为:

<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js" %>

我没有运气 - 似乎谷歌文件根本不存在(我检查了我的页面源并已加载)。我在这里做错了什么?

I currently have an ugly array of separate javascript files in one of my layouts and I'm trying to clean it up using the Google CDN.

Current state (horrible I know):

...css...  
<%= yield :head %>

<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" %>
<script type="text/javascript" src="http://cdn.jquerytools.org/1.2.5/all/jquery.tools.min.js"></script>
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js" %>
<%= javascript_include_tag "ui/jquery.ui.core", "ui/jquery.effects.core",
   "ui/jquery.effects.highlight", "ui/jquery.ui.widget", "ui/jquery.ui.tabs",
   "ui/jquery.ui.progressbar" %>
<%= javascript_include_tag "jquery.ui.stars.min", "application", "rails" %>

I tried replacing the 2nd from bottom tag (with the long list of files) with:

<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js" %>

I am getting no luck with that - it seems as if the google file is not there at all (I checked my page source and it is loaded). What am I doing wrong here?

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

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

发布评论

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

评论(2

再见回来 2024-11-24 13:45:10

我不知道如何将其转换为 RAILS,但这个简单的 HTML 应该可以解决问题。

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
    if(typeof jQuery == 'undefined') {
        //<![CDATA[
        document.write("<script src='/includes/jquery-1.4.2.min.js' type='text/javascript'><\/script>");
        //]]>
    }
</script>

这假设您的 jQuery 文件存储在 /includes/jquery-1.4.2.min.js 上。
当 Google 的 CDN 出现故障时,将获取本地副本。

I don't know how to translate it into RAILS but this simple HTML should do the trick.

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
    if(typeof jQuery == 'undefined') {
        //<![CDATA[
        document.write("<script src='/includes/jquery-1.4.2.min.js' type='text/javascript'><\/script>");
        //]]>
    }
</script>

This would assume that your jQuery file is stored on /includes/jquery-1.4.2.min.js.
On Google's CDN failure, local copy will get fetched.

梦醒时光 2024-11-24 13:45:10

很抱歉翻出旧帖子,但我不确定问题是否得到了真正的回答。

我遇到了和你类似的问题,解决方案实际上很简单:我没有包含 CSS。您也可以通过 Google 的 CDN 来做到这一点:

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css" media="screen" rel="stylesheet" type="text/css" />

或者

<%= stylesheet_link_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css' %>

显然这是针对 ui-lightness 主题的; CDN 上还有其他可用主题(尽管不是全部)。我相信您可以通过 Google 快速搜索找到这些内容。

Sorry to dredge up an old post, but I'm not sure the question was actually answered.

I had a similar problem as you did, and the solution was actually quite simple: I was not including the CSS. You can do so through Google's CDN as well:

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css" media="screen" rel="stylesheet" type="text/css" />

or

<%= stylesheet_link_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css' %>

Obviously this is for the ui-lightness theme; there are other themes available on the CDN (though not all of them). I'm sure you can find those with a quick Google search.

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