网络路径参考 URI / 方案相对 URL
方案相对 URL(网络路径引用)是我刚刚发现的东西 - 您不指定 URL 的方案,它会从当前上下文中获取它。
例如: 将解析为
https://example.com/img.png
如果当前方案是 HTTPS 或 http://example.com/img.png
(如果不是)。
这似乎是解决在 SSL 页面上调用外部脚本或图像的烦人问题的一种非常简单的方法,而不会引发页面上某些内容不安全的可怕错误。
好处似乎很明显,但我似乎找不到关于此的大量信息,并且想知道是否有人有关于方案相对 URL 的经验或参考(好或坏)?
虽然我试图找出是否有任何浏览器会导致问题(我在 IE6-8、Chrome 和 Firefox 上都取得了成功),但我也有兴趣了解是否有人有在不同的环境中使用此功能的经验。语言。例如,如果您要在 ASP 中发出带有方案相对 URL 的 Response.Redirect
,它会起作用吗?
Scheme relative URLs (network-path references) are something that I've just found out about - where you don't specify the scheme of a URL and it picks it up from the current context.
For example:<img src="//example.com/img.png" />
will resolve to https://example.com/img.png
if the current scheme is HTTPS or http://example.com/img.png
if it is not.
This seems like a very easy way to resolve those pesky problems of calling an external script or image on an SSL page without bringing up the dreaded error that some content on a page is not secure.
The benefit seems obvious, but what I don't seem to be able to find is a huge amount of information on this and was wondering if anyone had any experience or references about scheme relative URLs (good or bad)?
Whilst I'm trying to discover if there are any browsers that this causes issues with (I've been successful with IE6-8, Chrome and Firefox), I'm also interested to find out if anyone has any experience using this in different languages. For example, would it work if you were to issue a Response.Redirect
with a scheme relative URL in ASP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
//example.com/img.png
是一个完全有效的 URI 语法,按照 RFC 3986:第 4.2 节。它与当前的方案相关,因此正如您所提到的,它在以下情况下非常有用:在 HTTP 和 HTTPS 之间切换,因为您不需要显式指定方案。
所有现代浏览器都可以理解该格式,包括 IE 6。
进一步阅读 Stack Overflow:
中用 // 替换 http:// 是否有效?
的源代码中使用 //
//example.com/img.png
is a perfectly valid URI syntax as per RFC 3986: Section 4.2.It is relative to the current scheme, and therefore as you mentioned, it can be very useful when switching between HTTP and HTTPS, because you won't need to explicitly specify the scheme.
All modern browsers will understand that format, including IE 6.
Further reading on Stack Overflow:
<script src="http://...">
?<script>
's source如果您想支持 IE 7 和 8,您可能需要考虑样式表的相对 URL 方案将导致它们被下载两次:
来源:http://www .stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/
If you want to support IE 7 and 8, you might want to consider that scheme relative URLs for stylesheets will cause them to be downloaded twice:
Source: http://www.stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/