0

Is it valid to do:

<script src="//example.com/file.js" />

instead of

<script src="http://example.com/file.js" />

or

<script src="https://example.com/file.js" />

The first is given as an example in facebook's documentation, and I'm wondering if its valid and if so, which browsers support it (all, or only the most recent, etc).

0

2 Answers 2

4

That's called a protocol-relative URL.
It will become HTTP or HTTPS, depending on the protocol of the current page.

It works in all browsers.

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

Comments

2

Yes, it's valid and it works too! This is what's called a Protocol Relative URL, which will use http:// or https:// based on the current page protocol.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.