using // instead of protocol://

Jacksonkr picture Jacksonkr · Oct 8, 2011 · Viewed 7.8k times · Source

Possible Duplicate:
Is it valid to replace with // in a <script src=“…”>?
Absolute URLs omitting the protocol (scheme) in order to preserve the one of the current page
Does using //www.example.com in Javascript chose http/https protocol automatically

I'm looking at some sample code from facebook and I see:

<script src="//connect.facebook.net/en_US/all.js"></script>

they use // instead of http:// -- is this something fancy that I don't know about yet?

Answer

duskwuff -inactive- picture duskwuff -inactive- · Oct 8, 2011

It's called a "protocol-relative URL". Similar to how a url starting with "/" is relative to the root of the current domain, a URL starting with "//" will link to the specified host and path, but using whatever protocol the current page was loaded using.

There's a nice description of them, and why they're useful, on the Wikimedia blog:

http://blog.wikimedia.org/2011/07/19/protocol-relative-urls-enabled-on-test-wikipedia-org/