5

Possible Duplicate:
Is it valid to replace with // in a <script src=“…”>?
Links start with two slashes

I've seen this on a few sites now. An easy example is to look at the Wikipedia landing page's source:

<link rel="shortcut icon" href="//en.wikipedia.org/favicon.ico" />
<link rel="apple-touch-icon" href="//upload.wikimedia.org/wikipedia/commons/f/f1/Wikipedia-mobile-icon.png" />
<link rel="copyright" href="//creativecommons.org/licenses/by-sa/3.0/" />

Is there some standard with starting external links with //? Is this just done to avoid having to download the extra https?: and save some characters because most browsers are smart enough to add the rest of the scheme on there own? Or is this a legitimate thing, maybe with some other reason?

Community
  • 1
  • 1
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • Not forcing the protocol, allowing SPDY when available? – Hauke Ingmar Schmidt Feb 10 '12 at 23:00
  • Heres another post on it: http://stackoverflow.com/questions/7273573/links-start-with-two-slashes – scott Feb 10 '12 at 23:01
  • 3
    Duplicate of [Is it valid to replace http:// with // in a – josh3736 Feb 10 '12 at 23:02
  • @his: A schemaless URL has nothing to do with SPDY. SPDY augments HTTP; it doesn't replace it. You'd never see *spdy://example.com/*. – josh3736 Feb 10 '12 at 23:27

3 Answers3

7

That is usually called protocol-relative URLs and allows for the browser to download the resource using the same protocol as the page was being loaded with. So if the user had loaded the page through a https url, the resources specified with // will be loaded through https, otherwise they are loaded through regular http.

One thing it can help you prevent is the ugly user-unfriendly message in older versions of IE, stating that the page contains both secure and non-secure resources.

Paul Irish has written a good blog post about this:

Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103
0

This allows you to download the resources without specifying http or https; it will use whatever you're currently using.

Ian Hunter
  • 9,466
  • 12
  • 61
  • 77
0

Not specifying a scheme in the URL will cause the browser to assume the current scheme. You can read a good article about this here:

http://paulirish.com/2010/the-protocol-relative-url/

This is the main benefit of it:

If the browser is viewing that current page in through HTTPS, then it'll request that asset with the HTTPS protocol, otherwise it'll typically* request it with HTTP. This prevents that awful "This Page Contains Both Secure and Non-Secure Items" error message in IE, keeping all your asset requests within the same protocol.

There are some quirks...

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

... but in general you can use this safely.

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228