URLs with // at the beginning

Posted by Michał ‘mina86’ Nazarewicz on 4th of December 2022

A quick reminder that relative URLs can start with a double slash and that this means something different than a single slash at the beginning. Specifically, such relative addresses are resolved by taking the schema (and only the schema) of the website they are on.

For example, the code for the link to my repositories in the site’s header is <a href="//github.com/mina86">Code</a>. Since this page uses https schema, browsers will navigate to https://github.com/mina86 if the link is activated.

This little trick can save you some typing, but more importantly, if you’re developing a URL parsing code or a crawler, make sure that it handles this case correctly. It may seem like a small detail, but it can have a lasting impact on the functionality of your code.