Absolute Paths beginning with two slashes

懵懂的女人 提交于 2019-12-04 06:02:18

问题


I noticed that Wikipedia links pointing to a path on a different Wikipedia subdomain use a link with the following syntax: //<SERVER_NAME>/<REQUEST_URI>. For example, a link from a file page to the file appears (for example) as //upload.wikimedia.org/wikipedia/en/9/95/Stack_Overflow_website_logo.png. I am familiar with absolute paths (thinking twice about that now) and relative paths and how to use them. However, I have never seen this use. I assume this points to a new server name using the current protocol. Is this correct? And is there an official name (or widely accepted name) for this?


回答1:


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: http://tools.ietf.org/html/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.




回答2:


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.

<script src="//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.



来源:https://stackoverflow.com/questions/8254646/absolute-paths-beginning-with-two-slashes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!