Question

What are the pros and cons of having protocols in your hyperlinks versus not having them in "a", "base" etc elements? When I store a significant amount of URIs in an XML file, a database or just in HTML documents I always feel inclined to leave out the http: and https: part of the URI because browsers, at least modern ones, will know what to do and usually, perhaps always, the webserver will be able to deal with the wrong protocol and refer to the correct one (between HTTP/HTTPS).

Was it helpful?

Solution

You seem to know about the pros of protocol-relative URIs.

Cons might be:

  • The links probably won’t work in a non-HTTP or non-HTTPS context (e.g., if your content is part of an email, or if your HTML page is opened locally)
  • Some older browsers don’t support protocol-relative URIs (e.g., Internet Explorer 6)
  • Some older browsers fetch protocol-relative linked resources twice, via HTTP and HTTPS (e.g., Internet Explorer 7+8)

Of course some resource should always be delivered via HTTPS, so don’t use protocol-relative URIs for these, enforce HTTPS instead.

And you should probably not use protocol-relative URIs for things like rel-canonical.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top