Question

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?

Was it helpful?

Solution

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/

OTHER TIPS

Basically it gives you the ability to spit out one URL and have it use whatever protocol is currently being used.

Facebook probably uses the same HTML code regardless of whether the user is on HTTP or HTTPS. It's a way to fully qualify the domain without specifying the protocol.

It's another type of relative URL, it uses the same protocol that the page is on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top