URI 中的方案是可选的吗?
最近,我被要求向网站添加一些 Woopra JavaScript,并注意到 URL 以双斜杠开头(即省略了方案)。我以前从未见过这个,所以我试图了解更多信息,但我真正能找到的唯一东西是 Woopra 常见问题解答中的一项:
设置中的 Woopra JavaScript 脚本的 URL 调用中不包含 http。这是正确的。 JavaScript 已经过优化,可以在您的网站上快速高效地运行。
但是,某些验证和站点测试/调试服务和工具无法识别代码是否正确。这是正确且有效的。如果警告让您烦恼,只需将 http 添加到脚本的 URL 中即可。它不会影响脚本。
(为了澄清起见,URL 是“//static.woopra.com/js/woopra.v2.js”——除了“http”之外,还省略了冒号。)
是否有关于此做法的更多信息?如果这确实有效,那么一定有一个规范来讨论它,我非常希望看到它。
预先感谢您满足我的好奇心!
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:
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.
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.
(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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个有效的 URL。它被称为“网络路径引用”,如 RFC 3986 中定义。当您不指定方案/协议时,它将回退到当前方案。因此,如果您通过 https:// 查看页面,所有网络路径引用也将使用 https。
例如,这里是再次指向 RFC 3986 文档的链接,但带有网络路径参考。如果您通过 https 查看此页面(尽管看起来您无法在 StackOverflow 中使用 https),则该链接将反映您当前的 URI 方案,这与第一个链接不同。
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.
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.
请参阅 RFC 3986,第 3 节:
See RFC 3986, section 3: