Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
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
    
@daGrevis: Magic. –  grawity Sep 29 '11 at 16:59

3 Answers 3

up vote 4 down vote accepted

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.

share|improve this answer
    
I think that nowadays they will even try https:// first. –  Simon Verbeke Feb 15 '13 at 21:00

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

share|improve this answer

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/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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