Automatic Browser Protocol Detection

When designing websites, you normally don’t want to hard code any link or references to files. For example, if you reference an image, you should do so as

[cc lang=”html”]/images/header.jpg[/cc]

instead of

[cc lang=”html”]http://www.mysite.com/images/header.jpg[/cc]

But, what if you are referencing an image on a remote server? Well, instead of hard-coding the protocol like this:

[cc lang=”html”]http://www.anothersite.com/images/header.jpg[/cc]

you can just do this

[cc lang=”html”]//www.anothersite.com/images/header.jpg[/cc]

This way, if your visitor is accessing your site over SSL as in

[cc lang=”html”]https://www.mysite.com[/cc]

then the browser will automatically use https: when fetching the image on the remote server as in

[cc lang=”html”]https://www.anothersite.com/images/header.jpg[/cc]