以“//”开始外部站点链接
可能的重复:
替换为 // 是否有效在
我现在在一些网站上看到过这种情况。一个简单的例子是查看维基百科登陆页面的源代码:
<link rel="shortcut icon" href="//en.wikipedia.org/favicon.ico" />
<link rel="apple-touch-icon" href="//upload.wikimedia.org/wikipedia/commons/f/f1/Wikipedia-mobile-icon.png" />
<link rel="copyright" href="//creativecommons.org/licenses/by-sa/3.0/" />
是否存在以 //
开头外部链接的标准?这样做是否只是为了避免下载额外的 https?:
并保存一些字符,因为大多数浏览器都足够智能,可以自行添加方案的其余部分?或者这是一件合法的事情,也许还有其他原因?
Possible Duplicate:
Is it valid to replace with // in a <script src=“…”>?
Links start with two slashes
I've seen this on a few sites now. An easy example is to look at the Wikipedia landing page's source:
<link rel="shortcut icon" href="//en.wikipedia.org/favicon.ico" />
<link rel="apple-touch-icon" href="//upload.wikimedia.org/wikipedia/commons/f/f1/Wikipedia-mobile-icon.png" />
<link rel="copyright" href="//creativecommons.org/licenses/by-sa/3.0/" />
Is there some standard with starting external links with //
? Is this just done to avoid having to download the extra https?:
and save some characters because most browsers are smart enough to add the rest of the scheme on there own? Or is this a legitimate thing, maybe with some other reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这通常称为协议相关 URL,允许浏览器使用与加载页面相同的协议来下载资源。因此,如果用户通过
https
url 加载页面,则//
指定的资源将通过https
加载,否则将加载通过常规的http
。它可以帮助您防止的一件事是旧版本 IE 中出现丑陋的用户不友好消息,指出该页面包含安全和非安全资源。
Paul Irish 就此写了一篇很好的博文:
That is usually called protocol-relative URLs and allows for the browser to download the resource using the same protocol as the page was being loaded with. So if the user had loaded the page through a
https
url, the resources specified with//
will be loaded throughhttps
, otherwise they are loaded through regularhttp
.One thing it can help you prevent is the ugly user-unfriendly message in older versions of IE, stating that the page contains both secure and non-secure resources.
Paul Irish has written a good blog post about this:
这样您就可以在不指定http或https的情况下下载资源;它将使用您当前正在使用的任何内容。
This allows you to download the resources without specifying http or https; it will use whatever you're currently using.
不在 URL 中指定方案将导致浏览器采用当前方案。您可以在这里阅读一篇关于此的好文章:
http://paulirish.com/2010/ the-protocol-relative-url/
这是它的主要好处:
有一些怪癖...
...但一般来说您可以安全地使用它。
Not specifying a scheme in the URL will cause the browser to assume the current scheme. You can read a good article about this here:
http://paulirish.com/2010/the-protocol-relative-url/
This is the main benefit of it:
There are some quirks...
... but in general you can use this safely.