URI 中的方案是可选的吗?

发布于 2024-09-10 06:00:52 字数 576 浏览 0 评论 0原文

最近,我被要求向网站添加一些 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 技术交流群。

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

发布评论

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

评论(2

孤独岁月 2024-09-17 06:00:52

这是一个有效的 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.

苏佲洛 2024-09-17 06:00:52

请参阅 RFC 3986,第 3 节:

通用 URI 语法由
组件的分层序列
称为计划、机构、
路径、查询和片段。

 URI = 方案 ":" hier-part [ "?"查询] [“#”片段

]

 hier-part = "//" 权限路径-abempty
              / 绝对路径
              / 无根路径
              / 路径为空

方案和路径组件是
必需的,尽管路径可能是
空(无字符)。

See RFC 3986, section 3:

The generic URI syntax consists of a
hierarchical sequence of components
referred to as the scheme, authority,
path, query, and fragment.

  URI         = scheme ":" hier-part [ "?" query ] [ "#" fragment

]

  hier-part   = "//" authority path-abempty
              / path-absolute
              / path-rootless
              / path-empty

The scheme and path components are
required, though the path may be
empty (no characters).

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