Search code examples
httphref

whats the difference between make a href with http://domain vs //domain?


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


Solution

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