Protocol Relative URLs

Ever use a script that had a url without the http like this?

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:

div { background: url(//; }

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.



Get more great content like this, enter your email below.


Loading comments...

Leave a comment

Your email address will not be published. Required fields are marked *