5

I just noticed that I can write //google.com instead of http://google.com and it still works.

Is that some kind of short-hand? Maybe it's something that's built in my browser (Chrome 14)?

Is it safe to use double-slash instead of http and https?

6
  • 1
    You could probably just use google.com or superuser.com or codegolf.stackexchange.com
    – Rob
    Sep 29, 2011 at 15:52
  • What @Rob said - I don't think ANY modern browser has required you to put in the http:// in like, 10 years - it's just assumed. (If you want a different protocol from HTTP you do have to enter it.)
    – Shinrai
    Sep 29, 2011 at 15:53
  • The question was... why does it work? :D
    – daGrevis
    Sep 29, 2011 at 15:58
  • You may also be interested in google then Ctrl+Enter. Sep 29, 2011 at 16:09
  • 1
    @Shinrai: The question was about using a nonstandard // instead of http://, not about omitting it entirely. Sep 29, 2011 at 17:02

3 Answers 3

3

How something like // is handled by the browser will vary by browser. As the standard usage case is http:// and would work across all browsers without a problem.

That being said, the majority of browsers will attempt HTTP where possible since that is what the browsers are used most often for. It is also the safest choice, HTTP traffic is sandboxed as best as possible by the browser and should be more secure than assuming the address is local.

2
  • 1
    I think that nowadays they will even try https:// first. Feb 15, 2013 at 21:00
  • 6
    I don't see how this answers the question. It's also unclear what "HTTP traffic is sandboxed" means.
    – Brandon
    Dec 27, 2014 at 18:54
17

// is supported in all major browsers. Its very useful when you are developing a web based application and need to write code that works for both HTTP and HTTPS.

You could write for example: <script src="//myscript.js" /> and it will always work no matter which protocol you are using.

1
  • 3
    This should be the accepted answer.
    – tapananand
    May 26, 2016 at 17:18
7

I realize this question is old, but the accepted answer does not really answer the question.

Is that some kind of short-hand? Maybe it's something that's built in my browser (Chrome 14)?

Yes, it's a short-hand for whichever protocol the document was served over. It avoids the dreaded "This page contains both secure and nonsecure items. Do you want to display the nonsecure items?" message.

Is it safe to use double-slash instead of http and https?

Yes, all major browsers today support it.

It's generally useless against your own site, but can be very helpful for including resources from other sites (where absolute URL's are needed) but not having to worry about HTTP/HTTPS mix-mode.

It's also helpful if your document is served from both secure and nonsecure locations, like a dev site and production site.

For details, see http://www.paulirish.com/2010/the-protocol-relative-url/ (although that site does not recommend this technique any more, recommends to always use HTTPS)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .