HTTPS and external (CDN) hosted files?

前端 未结 2 1547
抹茶落季
抹茶落季 2020-12-01 07:40

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 pa

相关标签:
2条回答
  • 2020-12-01 08:28

    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

    0 讨论(0)
  • 2020-12-01 08:32

    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.

    0 讨论(0)
提交回复
热议问题