Using // instead of http://


I have seen people using // instead of http:// when including js/css in their page…anyone know why?

<script type="text/javascript"


If your page is requested over https, you’ll get a warning about including non-secure content if you link scripts over http. By starting your links with //, the browser will use the same protocol that the page is served by.

It’s a scheme relative URL. So if your page is https, then the js/css request will also be https. Works everywhere, I believe, except that I’ve read IE8 will issue the request twice, which would be detrimental to performance since the number of HTTP requests is one of the most significant factors. But if IE8 isn’t a concern, then there’s no reason you can’t use scheme relative URLs everywhere.

EDIT: People keep beating me to the punch lately. :slight_smile:

so will it even work if the page requesting is https and does not support https?

No, the server hosting the scripts must be able to serve them via https for that to work.

Edit: @Jeff Mott - I hadn’t heard that about IE8 before, that’s useful to know.

oh ok thanks everyone for the responses…

Does IE make double request, one for http and the other for https?? is it?

Just to clarify on the IE issue, according to this blog post by Paul Irish:

When used on a <link> or @import for a stylesheet, IE7 and IE8 download the file twice. All other uses, however, are just fine.