Why do CDN web addresses do not specify protocol?

11

Usually web addresses start with http:// or https:// , but CDN addresses such as jQuery and Bootstrap start with // .

Example:

<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

and

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

What does this mean?

    
asked by anonymous 15.04.2014 / 15:13

1 answer

11

This tells the browser to use the same protocol that is in the address bar of the page making the request.

That means:

  • If you are on a page served over HTTP, the request will be made to the HTTP CDN

  • If you are on a page served over HTTPS, the request will be made to the HTTPS CDN

Example

Suppose I have a site in www.meusite.com.br , and I put a reference in it as you indicated:

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

In IIS, I configure to allow my page to be served by both HTTP and HTTPS.

When the user accesses http://www.meusite.com.br , the browser fetches javascript in http://code.jquery.com/jquery-1.11.0.min.js .

When the user accesses https://www.meusite.com.br , the browser fetches javascript in https://code.jquery.com/jquery-1.11.0.min.js .

    
15.04.2014 / 15:15