admin管理员组

文章数量:1316645

I'm experiencing an issue with the jQuery CDN.

Given the following script imports:

<script type="text/javascript" src=".9.1.js"></script>
<script type="text/javascript" src=".10.3/jquery-ui.js"></script>

I am having the following issues with the CDN paths:

  1. Using http://... when accessing my site over SSL I get

    [blocked] The page at / ran insecure content from .9.1.js.

  2. Using https://... seems a bit dodgy if not accessing site over SSL
  3. Using //... causes both the imports to fail on GET.
What is the correct way of importing jQuery from CDN with a site that can be accessed both securely and not.

I'm experiencing an issue with the jQuery CDN.

Given the following script imports:

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

I am having the following issues with the CDN paths:

  1. Using http://... when accessing my site over SSL I get

    [blocked] The page at https://www.example./ ran insecure content from http://code.jquery./jquery-1.9.1.js.

  2. Using https://... seems a bit dodgy if not accessing site over SSL
  3. Using //... causes both the imports to fail on GET.
What is the correct way of importing jQuery from CDN with a site that can be accessed both securely and not.

Share Improve this question asked Sep 23, 2013 at 16:56 dav_idav_i 28.2k17 gold badges110 silver badges138 bronze badges 7
  • 2 how are you saying the third option is failing – Arun P Johny Commented Sep 23, 2013 at 16:59
  • 3 did you try <script type="text/javascript" src="//code.jquery./jquery-1.9.1.js"></script>, it seems fine plnkr.co/edit/6uFktr3TaBMWbEUdsvmZ?p=preview – Arun P Johny Commented Sep 23, 2013 at 16:59
  • 1 it will fail if you are loading the page from local file system instead of a web server – Arun P Johny Commented Sep 23, 2013 at 17:01
  • @ArunPJohny Ahh - would that happen even on a local IIS? – dav_i Commented Sep 23, 2013 at 17:03
  • no... if it is loading from a local web server with http:// or https:// address it will work fine – Arun P Johny Commented Sep 23, 2013 at 17:05
 |  Show 2 more ments

1 Answer 1

Reset to default 10

just omit the protocol, then the script will be loaded using the same protocol as the page

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

But if the resource is loaded form the file system(with file:// protocol) then this will not work

本文标签: javascriptjQuery CDN secureinsecure loading issuesStack Overflow