Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a URL start with "//"? [duplicate]

Tags:

http

url

https

ssl

Possible Duplicate:
Is it valid to replace with // in a <script src=“…”>?

We have a site on http[s]://A.example.com/ that references some resources (JS and CSS) on http[s]://A.example.com/

It makes sense, and avoids some browser warnings, if the same scheme is used when referencing the resources as the main site A is using. Site A uses PHP, so we can programmaticly detect the current scheme (http or https) and insert that into the header of the page.

However, we have found that just using '//' instead of the scheme also works.

So site A may reference "//B.example.com/theme/main.css" without a problem in all browsers we have tried, regardless of whether we go to site A using http or https.

My question is: is this a valid URL? It seems to work, but I cannot find anyone else doing it, and I cannot find any examples of this being suggested or recommended.

like image 270
Jason Avatar asked Aug 30 '12 17:08

Jason


1 Answers

Yes. It is called a protocol-relative URL. See also Can I change all my http:// links to just //?

like image 191
Bergi Avatar answered Oct 20 '22 20:10

Bergi