A nice trick to avoid insecure content warnings on pages that could be either http
or https
is to reference all scripts or assets in the code using "//" which will use the current page protocol instead of a specified one.
If one enters a URL with //
in the front directly into a browser URL box, is there a default behavior the browser will pick? Would/should it default to http
or https
, or some set of rules to test and pick one over the other?
A network-path reference (e.g.,
//example.com/
) is a relative reference. For resolving a relative reference, a base URI is necessary.When entering a network-path reference into a browser’s address bar, no such base URI can be established with the first three ways, so the fourth way, 5.1.4. Default Base URI, applies:
In other words, it’s up to each browser.
If a browser would only support
http
andhttps
, it would likely choose the same scheme that gets used when users enter something like "www.example.com", so probablyhttp
(see Suffix Reference). But many browsers support more schemes.For example, on my system, requesting
//example.com/test
resolves to a URI using thefile
scheme:file:////example.com/test
(Firefox),file:///example.com/test
(Chromium).