HTTPS和外部(CDN)托管文件? [英] HTTPS and external (CDN) hosted files?

查看:176
本文介绍了HTTPS和外部(CDN)托管文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面引用了两个外部托管的javascript文件-即 jQuery on Google 使用YUI加载程序的YUI .

I have a page that references a couple of externally hosted javascript files - namely, jQuery on Google and YUI using YUI Loader.

问题是当我通过HTTPS访问页面时,浏览器抱怨混合的不安全内容,因为外部javascript文件是使用http而不是https来访问的.

The trouble is when I access the page via HTTPS the browser complains of mixed insecure content, since the external javascript files are being accessed using http instead of https.

使用HTTPS访问外部jQuery和YUI加载程序对象是解决此问题的一种好方法吗?

What's a good way to deal with this, accessing the external jQuery and YUI Loader objects with HTTPS?

推荐答案

假设CDN提供程序具有https版本,则可以使用协议相对URL.

Assuming the CDN provider has an https version, you can use protocol-relative URLs.

例如,代替:

http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js

...您可以使用:

//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js

浏览器将使用页面的协议来尝试获取文件.在非安全页面上,http.在安全页面上,https.

The browser will use the page's protocol to try to obtain the file. On non-secure pages, http. On secure pages, https.

Google还通过其CDN提供了YUI加载程序.因此,对于YUI来说,它工作正常:

Google also makes YUI Loader available through its CDN. So for YUI this works fine:

//ajax.googleapis.com/ajax/libs/yui/2.8.0/build/yuiloader/yuiloader-min.js

...在http和https上下文中.

...in both http and https contexts.

这篇关于HTTPS和外部(CDN)托管文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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