12

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?

10
  • 5
    I swear this is a duplicate of a very well-known question with extreme votes, but I understand if you searched and couldn't find the original question because neither can I. Commented Oct 7, 2011 at 22:55
  • 1
    This post answers the question stackoverflow.com/questions/3583103/scheme-relative-urls , but if you don't know to search for scheme relative URL, you wouldn't find it Commented Oct 7, 2011 at 22:57
  • @BoltClock I know the exact question question you're talking about, but I can't find it either. Commented Oct 7, 2011 at 23:01
  • @JuanMendes: Well, typing "javascript" plus the title of this question brought me to this answer. Commented Oct 7, 2011 at 23:09
  • 1
    @Ӫ_._Ӫ: Even though this question really has nothing to do with JS... Commented Oct 7, 2011 at 23:11

3 Answers 3

18

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/

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.