只需使用//example.com/foo.blah即可.
< img id =“sample-image”src =“// /media/sample-image.png”/>
很明显,HTTP是协议,但存在其他协议,如GOPHER,HTTPS,FTP等……
而不是在gopher URL gopher://example.com上,您只需链接到//example.com,协议就可以在没有它的情况下工作.如果要从HTTPS链接到HTTP内容,则应指定协议.
从长远来看,这可能是有趣的,例如,如果另一个协议出现与HTTP几乎相同的工作(例如,谷歌试图制作spdy://),您将不得不更新所有代码.当您特别需要从该协议获取内容时使用特定协议,您可能会在未来5年内避免此问题.
RFC for URL,RFC3986中描述了相对URL:
4.2. Relative Reference
A relative reference takes advantage of the hierarchical syntax
(Section 1.2.3) to express a URI reference relative to the name space
of another hierarchical URI.
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
relative-part = "//" authority path-abempty
/ path-absolute
/ path-noscheme
/ path-empty
The URI referred to by a relative reference, also known as the target
URI, is obtained by applying the reference resolution algorithm of
Section 5.
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.
A path segment that contains a colon character (e.g., “this:that”)
cannot be used as the first segment of a relative-path reference, as
it would be mistaken for a scheme name. Such a segment must be
preceded by a dot-segment (e.g., “./this:that”) to make a relative-
path reference.
要了解“路径”,“权限”和“方案”的含义,请参阅同一RFC中的图表:
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
| _____________________|__
/ \ / \
urn:example:animal:ferret:nose
所有这一切都假设您正在使用多个域,因为有关< img src =“./ relative / url / foo.png”>的问题.或img src =“/ absolute / path / while / domain / relative / foo.png”已多次回答.