Protocol Relative URLs

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

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>

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(//mysite.com/image.jpg); }

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/


Get more content like this

Get valuable insight on business and money in your inbox once per week.

Posted by Scott

Leave a Reply

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

Being a business owner is hard. I'm trying to get better in business and life, enter your email if you want to join me.
Holler Box