1

I was checking some docs and a customer asked me to change some links at the best way... right now they are only as //domain.com and i want to know whats the difference between use http://domain.com than only //domain.com , could also be /domain.com ?

would be a problem if i use only // for some old browsers or if use only one / ?

Currently I am trying with //domain.com only, but I havent checked if older browsers work correctly with this.

Any idea? Thanks

jpganz18
  • 5,508
  • 17
  • 66
  • 115
  • possible duplicate of [Can I change all my http:// links to just //?](http://stackoverflow.com/questions/4831741/can-i-change-all-my-http-links-to-just) – Joe Sep 28 '14 at 11:01

2 Answers2

3

//domain.com doesn't include a protocol. So if you were linking to a script (or other resource) on another host, this is a nice way to provide the URL without having to manually change it between HTTP and HTTPS, the browser will use the current protocol that the page was accessed on. This is commonly used when linking to scripts or other resources hosted on a CDN.

In some browsers, if you try to use an HTTP hosted script when you've accessed the site via HTTPS, you'll get a message saying something about "Only secure content is displayed. [Show all content] [Close]" or something to that effect. It often confuses users, and using the protocol relative version of the URL helps avoid that issue.

mason
  • 31,774
  • 10
  • 77
  • 121
1

First of all, /domain.com would actually be a domain-relative link leading to http://domain.com/domain.com, so that's right out.

//domain.com/ is a _protocol-relative URL, meaning, that if this URL is found on HTTP pages, the final URL will be http://domain.com, while, if the URL is found on HTTPS pages, the resulting URL will be https://domain.com.

http://domain.com/ is an absolute URL and will stay this way forever.

Denis
  • 5,061
  • 1
  • 20
  • 22
  • so, if i have only / but the links refer the same domain im located, would be actually faster? – jpganz18 Sep 25 '14 at 16:13
  • You will never find a noticable performance difference here and should not worry about it. "Premature optimization is the root of all evil". – Denis Sep 25 '14 at 16:44