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?

  • 1
    You could probably just use google.com or superuser.com or codegolf.stackexchange.com – Rob Sep 29 '11 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 '11 at 15:53
  • The question was... why does it work? :D – daGrevis Sep 29 '11 at 15:58
  • You may also be interested in google then Ctrl+Enter. – RedGrittyBrick Sep 29 '11 at 16:09
  • @Shinrai: The question was about using a nonstandard // instead of http://, not about omitting it entirely. – user1686 Sep 29 '11 at 17:02

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.

| improve this answer | |
  • I think that nowadays they will even try https:// first. – Simon Verbeke Feb 15 '13 at 21:00
  • 5
    I don't see how this answers the question. It's also unclear what "HTTP traffic is sandboxed" means. – Brandon Dec 27 '14 at 18:54

// 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.

| improve this answer | |
  • 2
    This should be the accepted answer. – tapananand May 26 '16 at 17:18

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/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.