Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

jquery - HTTPS and external (CDN) hosted files?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...