HTTPS and external (CDN) hosted files?

别来无恙 提交于 2019-12-28 02:44:09

问题


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

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.

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


回答1:


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

For example, instead of:

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

...you can use:

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

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

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

...in both http and https contexts.




回答2:


Google hosts them under https

https://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/yuiloader/yuiloader-min.js

https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js



来源:https://stackoverflow.com/questions/3622598/https-and-external-cdn-hosted-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!