URI 中的 Scheme 是可选的吗? [英] Is the Scheme Optional in URIs?

查看:43
本文介绍了URI 中的 Scheme 是可选的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近被要求向网站添加一些 Woopra JavaScript,并注意到 URL 以双斜杠开头(即省略了方案).我以前从未见过这个,所以我试图了解更多关于它的信息,但我唯一能真正找到的是 Woopra 常见问题解答中的一项:

I was recently asked to add some Woopra JavaScript to a website and noticed that the URL started with a double slash (i.e. omitted the scheme). I've never seen this before, so I went trying to find out more about it, but the only thing I could really find was an item on the Woopra FAQ:

安装程序中的 Woopra JavaScript 在脚本的 URL 调用中不包含 http.这是对的.JavaScript 已经过优化,可以在您的网站上快速高效地运行.

The Woopra JavaScript in the Setup does not include http in the URL call for the script. This is correct. The JavaScript has been optimized to run very fast and efficiently on your site.

但是,某些验证和站点测试/调试服务和工具无法将代码识别为正确.这是正确和有效的.如果警告惹恼了您,只需将 http 添加到脚本的 URL 中即可.它不会影响脚本.

However, some validation and site testing/debugging services and tools do not recognize the code as correct. It is correct and valid. If the warnings annoy you, just add the http to the script’s URL. It will not impact the script.

(为了澄清起见,URL 是//static.woopra.com/js/woopra.v2.js"——除了http"之外,还省略了冒号.)

(For clarification, the URL is "//static.woopra.com/js/woopra.v2.js"—the colon is omitted in addition to the "http".)

有没有关于这种做法的更多信息?如果这确实有效,那么必须有一个规范讨论它,我非常想看到它.

Is there any more information about this practice? If this is indeed valid, there must be a spec that talks about it, and I'd very much like to see it.

预先感谢您满足我的好奇心!

Thanks in advance for satisfying my curiousity!

推荐答案

这是一个有效的 URL.它被称为网络路径参考",如 RFC 3986 中所定义.当您不指定方案/协议时,它将回退到当前方案.因此,如果您通过 https://查看页面,则所有网络路径引用也将使用 https.

This is a valid URL. It's called a "network-path reference" as defined in RFC 3986. When you don't specify a scheme/protocol, it will fall back to the current scheme. So if you are viewing a page via https:// all network path references will also use https.

例如,这里是 RFC 3986 文档的链接,但带有网络路径参考.如果您通过 https 查看此页面(尽管看起来您无法在 StackOverflow 中使用 https),则该链接将反映您当前的 URI 方案,这与第一个链接不同.

For an example, here's a link to the RFC 3986 document again but with a network path reference. If you were viewing this page over https (although it looks like you can't use https with StackOverflow) the link will reflect your current URI scheme, unlike the first link.

这篇关于URI 中的 Scheme 是可选的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆