网络路径参考 URI / 方案相对 URL

发布于 2024-09-16 09:13:59 字数 527 浏览 7 评论 0原文

方案相对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

霓裳挽歌倾城醉 2024-09-23 09:13:59

//example.com/img.png 是一个完全有效的 URI 语法,按照 RFC 3986:第 4.2 节

它与当前的方案相关,因此正如您所提到的,它在以下情况下非常有用:在 HTTP 和 HTTPS 之间切换,因为您不需要显式指定方案。

所有现代浏览器都可以理解该格式,包括 IE 6。

进一步阅读 Stack Overflow:

//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:

怎樣才叫好 2024-09-23 09:13:59

如果您想支持 IE 7 和 8,您可能需要考虑样式表的相对 URL 方案将导致它们被下载两次:

[...]如果您在 Internet Explorer 7 和 8 中尝试此操作,您将看到使用协议相对 URL 指定的样式表被下载两次。

如果开发人员希望其页面在 Internet Explorer 7 和 Internet Explorer 中尽可能快,则应避免在样式表中使用协议相对 URL。 8.

来源: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:

[...] if you try this in Internet Explorer 7 and 8 you’ll see that stylesheets specified with a protocol relative URL are downloaded twice.

Developers should avoid using protocol relative URLs for stylesheets if they want their pages to be as fast as possible in Internet Explorer 7 & 8.

Source: http://www.stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文