5 ms·
Actually, the double slash is useful for at least one thing. You can use it in web pages to make relative URLs which preserve the protocol, but change the serve
by chrismear 17y ago
Actually, the double slash is useful for at least one thing. You can use it in web pages to make relative URLs which preserve the protocol, but change the server.
Suppose you have pages on a server www.example.com that reference images on an asset host assets.example.com. Usually, you would use a full URL in your HTML to reference your images:
http://assets.example.com/image.png http://assets.example.com/image.png
This is fine if all your accesses to www.example.com are done over HTTP. But what if you want to use HTTPS sometimes? Unless you change those URLs to use the HTTPS protocol as well, the browser may give the 'mixed secure and insecure content' warning.
If you specify the image URLs as relative URLs in the form:
//assets.example.com/image.png
then when a user visits http://www.example.com/ http://www.example.com/ their browser will fetch the image from http://assets.example.com/image.png http://assets.example.com/image.png . But when they visit https://www.example.com/ https://www.example.com/ their browser will fetch the image from https://assets.example.com/image.png https://assets.example.com/image.png .
Without the double slash, this kind of relative URL would be indistinguishable from the more common relative URL which just means a different path on the same server:
/assets.example.com/image.png