Skip to content Skip to sidebar Skip to footer

Absolute Paths Beginning With Two Slashes

I noticed that Wikipedia links pointing to a path on a different Wikipedia subdomain use a link with the following syntax: ///. For example, a

Solution 1:

You are absolutely right. A link to //some/path is a protocol relative path.

Namely, if you are currently on http://something.example.com, a link to //google.com would point to http://google.com.

If you are currently on https://something.example.com, a link to //google.com would point to https://google.com.

The most common use of this can be seen in the html5 boilerplate.

<scriptsrc="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>

Kindly google provides its javascript cdn over both http and https. Thereby to avoid security warnings, we load it over https if we are on https, or http if we are on http.

note:

Unfortunately, you can't do the same thing for google analytics.

they use the domains ssl.google-analytics.com and www.google-analytics.com for https and http.

Solution 2:

It looks like these //example.com URIs are called "Scheme Relative" or "Protocol Relative", and there is more information about it at this question:

Network-Path Reference URI / Scheme relative URLs

EDIT:

Apparently this might actually be called a "network-path reference" as seen here: https://www.rfc-editor.org/rfc/rfc3986#section-4.2

Quote:

A relative reference that begins with two slash characters is termed a network-path reference; such references are rarely used. A relative reference that begins with a single slash character is termed an absolute-path reference. A relative reference that does not begin with a slash character is termed a relative-path reference.

Post a Comment for "Absolute Paths Beginning With Two Slashes"