URL开始时双重斜线?

发布于 2025-02-03 05:18:36 字数 871 浏览 3 评论 0原文

我目前正在研究一个Chrome扩展程序,该扩展使我能够下载已在网页上使用的字体文件。

当我解析的字体时字体URL。

对于字体freddy @font-face规则看起来像这样:

@font-face {
font-family: 'Freddy';
src: url("//cdn.shopify.com/s/files/1/0548/8708/8184/t/24/assets/freddy_regular_2-webfont.woff?v=147712666987587936441646682936") format("woff") , 
  url("//cdn.shopify.com/s/files/1/0548/8708/8184/t/24/assets/Freddy_Regular_2.ttf?v=64870238297763773461646682938") format("truetype") , 
  url("//cdn.shopify.com/s/files/1/0548/8708/8184/t/24/assets/freddy_regular_2-webfont.woff2?v=66678714148373221751646682937") format("woff2"); /* Safari, Android, iOS */}

这打破了我的脚本,因为双斜线使其成为无效的URL(即如果我将其输入到浏览器中这会给我一个错误)。

所以我想知道 - 此URL开始时双重砍伐的目的是什么?如果它似乎是无效的URL,这实际上如何检索字体?

I'm currently working on a chrome extension that allows me to to download the fonts files that have been used on a webpage.

As I was parsing the fonts for this site I ran into a strange edge case for one of the font URLs.

For the font Freddy the @font-face rule looks like this:

@font-face {
font-family: 'Freddy';
src: url("//cdn.shopify.com/s/files/1/0548/8708/8184/t/24/assets/freddy_regular_2-webfont.woff?v=147712666987587936441646682936") format("woff") , 
  url("//cdn.shopify.com/s/files/1/0548/8708/8184/t/24/assets/Freddy_Regular_2.ttf?v=64870238297763773461646682938") format("truetype") , 
  url("//cdn.shopify.com/s/files/1/0548/8708/8184/t/24/assets/freddy_regular_2-webfont.woff2?v=66678714148373221751646682937") format("woff2"); /* Safari, Android, iOS */}

This broke my script because the double slash makes it an invalid URL (i.e. if I type it into the browser as is it will give me an error).

So I was wondering — what's the purpose of the double slashes at the beginning of this URL? How does this actually retrieve the font if it seems to be an invalid URL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

百变从容 2025-02-10 05:18:36

在另一个域中引用内容时,请使用两个斜率启动URL,而不是httphttps协议告诉浏览器使用与源页面相同的协议请求URL的内容(要预防混合内容)。

这些URL并不是要输入地址栏,这就是为什么当您尝试直接导航到它时它们似乎是无效的URL的原因。

When referencing content on another domain, starting a URL with two slashes instead of the http or https protocol tells the browser to request the URL's content using the same protocol as the source page (to prevent mixed content).

These URLs are not meant to be typed into an address bar, which is why they appear to be an invalid URL when you try navigating directly to it.

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