【问题标题】:jQuery CDN secure/insecure loading issuesjQuery CDN 安全/不安全加载问题
【发布时间】:2013-09-28 16:14:48
【问题描述】:

我在使用 jQuery CDN 时遇到问题。

鉴于以下脚本导入:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

CDN 路径存在以下问题:

  1. 通过 SSL 访问我的网站时使用 http://... 我得到

    [已阻止]https://www.example.com/ 的页面运行了来自 http://code.jquery.com/jquery-1.9.1.js 的不安全内容。

  2. 如果不通过 SSL 访问站点,使用 https://... 似乎有点狡猾
  3. 使用 //... 会导致两个导入都在 GET 上失败。
从 CDN 导入 jQuery 的正确方法是什么,该站点可以安全访问,也可以不安全访问。

【问题讨论】:

  • 你怎么说第三个选项失败了
  • 你试过了吗&lt;script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt;,好像还不错plnkr.co/edit/6uFktr3TaBMWbEUdsvmZ?p=preview
  • 如果您从本地文件系统而不是 Web 服务器加载页面,它将失败
  • @ArunPJohny Ahh - 即使在本地 IIS 上也会发生这种情况?
  • 不...如果它是从具有http:// 或https:// 地址的本地Web 服务器加载的,它将正常工作

标签: javascript jquery html ssl


【解决方案1】:

只需省略协议,那么脚本将使用与页面相同的协议加载

<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

但是如果资源是从文件系统加载的(使用 file:// 协议)那么这将不起作用

【讨论】:

    猜你喜欢
    • 2014-08-19
    • 1970-01-01
    • 2022-07-08
    • 2016-12-10
    • 2014-01-31
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    相关资源
    最近更新 更多