Protocol Relative URLs

Ever use a script that had a url without the http like this?
[javascript][/javascript]
I always wondered what that was about. Turns out it allows your browser to download the resource through http or https, which gets rid of any pesky warning messages about “Non-secure items” when viewing an https page.

You can use this pretty much anywhere, including in stylesheets:
[css]div { background: url(//mysite.com/image.jpg); }[/css]
There is one caveat, according to Paul Irish: “Caveat: When used on a or @import for a stylesheet, IE7 and IE8 download the file twice. All other uses, however, are just fine.”
It works in everything except IE6, and nobody cares about IE6 users, so you’re good.
Source: http://www.paulirish.com/2010/the-protocol-relative-url/


Posted

in

by

Tags: