Cons and Pros of Protocol-Less-Urls "//example.org" vs "http://www.example.org"

The main reason to use these URLs are in a site that uses both HTTP and HTTPS (with the same page). The idea being that links to static content on the page use // instead of http://, inheriting the protocol from the page. This allows the client to add the correct protocol (so secure pages don't have "insecure items" on them) and removes the need to code two versions of the page or have special "tricks" to change the protocol when the page is generated.

For any URL outside of this, not adding a protocol will mean that users may directly come to your site with an HTTPS request, adding unnecessary load to your site. I suggest explicitly specifying the protocol in such cases.


As for the issue of using www or not - it depends on what else you will have on the server and if you expect subdomains (if you add a blog, will it have a blog.example.com URL or an example.com/blog URL). If you do expect subdomains, use www to signify main site, if you don't you can omit it.


With regard to using www.example.com or example.com for a website, there are good reasons to use both. Some argue that the only real thing people will be using your domain name for is to go to your webserver, thus www. is considered redundant by those of that opinion.

I personally prefer www.example.com as one can create a CNAME record for that. This is useful if you ever want/need to put a website behind a CDN, as root domain names cannot be CNAMEs.

In either case, you would most likely want the one you are not using to give redirects to whichever you are using so regardless of where a user hits they will get to the server.

As for why people don't use //example.com or //www.example.com my guess would be:

  • The thought of a link without a protocol is scary and seems odd...
  • Most markup parsers probably don't recognize it, either.

Tags:

Http

Url