News for hackers. Stuff that matters.
Re:"//" should indicate a URL by nbpoole on Sunday June 26, 2011 @11:56PM (#2700040)
The // prefix is actually used for protocol-relative URLs. So //google.com leads to https://google.com on a page with SSL, and it leads to http://google.com on an unencrypted page.

See:

http://nedbatchelder.com/blog/200710.html#e20071017T215538

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

Re:"//" should indicate a URL by rufibarbatus on Monday June 27, 2011 @12:23AM (#2700106)
Conversely, the protocol bit is relevant whenever your link is not domain- or protocol-relative, or when you can't be sure.

And you can't be sure. Here's why: if someone saves your page on their hard drive and you're using protocol-relative URLs, the implied "http" just became "file". (Which in fact may be a nice excuse for some clever hacks.)

Test it yourself! Save the following snippet to your computer and see how your browser resolves the URL:

  <!DOCTYPE html>
  <title>Testing 1 2 3</title>
  <p><a href="//google.com/">Linky</a></p>
Re:"//" should indicate a URL by sjs on Monday June 27, 2011 @12:42AM (#2700148)
You're assuming people care about that use case. I think in most cases it's irrelevant.
Re:"//" should indicate a URL by Vivtek on Monday June 27, 2011 @06:54AM (#2700865)
Oh man. Are you really saying that corner cases are a priori negligible? That seems like a dangerous road to start down when you're discussing basic protocols!
Re:"//" should indicate a URL by sjs on Monday June 27, 2011 @12:43PM (#2701930)
If your use case entails people saving your site to disk then you have may not be able to use // for protocol relative links, but most people don't have to worry about such things.

I'm saying that those who need to worry about such things should and the rest of us should not. Nothing more and nothing less.

Re:"//" should indicate a URL by teyc on Monday June 27, 2011 @03:09AM (#2700442)
HTML Base tag is your friend. http://www.w3schools.com/TAGS/tag_base.asp
Re:"//" should indicate a URL by sleepyhead on Monday June 27, 2011 @04:40AM (#2700614)
W3Schools is not your friend. http://w3fools.com/
Re:"//" should indicate a URL by rufibarbatus on Monday June 27, 2011 @08:19AM (#2701028)
And here it is in the specification:

http://dev.w3.org/html5/spec/Overview.html#the-base-element

And accordingly, adding `<base href="http://example.com/ >` to that test above seems to work well on modern browsers.

Re:"//" should indicate a URL by rawsyntax on Monday June 27, 2011 @12:46AM (#2700154)
wget has switches to replace http with file when saving a website to disk
Re:"//" should indicate a URL by astrodust on Monday June 27, 2011 @12:12AM (#2700078)
Doesn't seem like it would be that abusive for it to end up being "auto-detect" when there is nothing to be relative to.

A "//" link in an HTTPS site would be required to be the same protocol anyway. It's only the spdy->http fallback that could prove to be a nuisance.

Re:"//" should indicate a URL by nyellin on Monday June 27, 2011 @12:43AM (#2700149)
Cool, I didn't know that.

// has another meaning in XML XPath, a language for navigating XML documents. // selects nodes anywhere in a document. For example, //p would select all paragraphs in an XHTML page.

Re:"//" should indicate a URL by jonursenbach on Monday June 27, 2011 @01:36AM (#2700276)
The problem with this is that browsers that are older than IE8 don't support it, so if you're still targeting those users you're SOL on this method.
Re:"//" should indicate a URL by jonhohle on Monday June 27, 2011 @02:16AM (#2700364)
I've used this technique since 2006 or so with IE6. The only concern I know of relates to using odd port numbers without a protocol in IE (but I don't think this is a concern if the protocol is relative). At the time, every other browser tested worked as well (not that that was much of a shock).

I don't have a copy of IE6 to test on at the moment, but what makes you think IE8 is required for relative protocols?

Re:"//" should indicate a URL by ryanpetrich on Monday June 27, 2011 @03:23AM (#2700469)
IE6 will also fetch some resources twice if they are protocol-relative URLs
Re:"//" should indicate a URL by justincormack on Monday June 27, 2011 @05:58AM (#2700771)
That doesn't wound like a shopstopper... optimising performance for IE6 is kind of pointless..