What is the difference between http:// and // in w

2019-05-04 16:14发布

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.

3条回答
时光不老,我们不散
2楼-- · 2019-05-04 16:47

// is "Whatever the current protocol is".

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

查看更多
【Aperson】
3楼-- · 2019-05-04 16:50

// is a protocol-less url. it will use http or https depending on the browser's connection.

There is a good explanatory article of why you would want to do this here: http://encosia.com/2011/01/19/cripple-the-google-cdns-caching-with-a-single-character/

查看更多
Evening l夕情丶
4楼-- · 2019-05-04 16:52

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.

查看更多
登录 后发表回答