Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between http:// and // in web development? [duplicate]

Possible Duplicate:
Can I change all my links to just //?

I came across this recently whilst poking around the markup for Google's 404 page. In it, they use // at the start of their URLs, in anchors in the markup, as well as referencing images/etc in their CSS.

Since it's not something I've come across before, and given that Google is notorious at finite-detail optimisation, I thought I'd ask here and see if anyone has any more information on the use of // instead of http:// it's not something that can be easily Googled about to find an answer.

I'm aware that // is useful in applications where either http or https might come into play, but apart from that, are there other benefits? Is it supported by all browsers? Are there any use limitations? Is it new/old?

I'd be really interested if anyone has any information.

like image 539
johnkavanagh Avatar asked Nov 29 '22 04:11

johnkavanagh


2 Answers

// is "Whatever the current protocol is".

On a page served over http, it is http://, and over https it is https://.

like image 173
Quentin Avatar answered Dec 08 '22 01:12

Quentin


The only downside I could find is this:

http://www.stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/

Internet Explorer 7 & 8 will download stylesheets twice if the http(s) protocol is missing.

..

A protocol relative URL doesn’t contain a protocol. For example,

http://stevesouders.com/images/book-84x110.jpg
becomes
//stevesouders.com/images/book-84x110.jpg

Browsers substitute the protocol of the page itself for the resource’s missing protocol.

..

However, if you try this in Internet Explorer 7 and 8 you’ll see that stylesheets specified with a protocol relative URL are downloaded twice. Hard to believe, but true.

I just tested it with Wireshark and IE8, and it's true.

So, if you care about having a performant website, avoid using // with CSS.

like image 45
thirtydot Avatar answered Dec 08 '22 01:12

thirtydot