简体   繁体   English

你应该对样式表使用预连接吗?

[英]Should you use preconnect with stylesheets?

When you want to include a font from Google Fonts it suggests you do it like this:当您想包含来自 Google Fonts 的字体时,它建议您这样做:

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto&display=swap">

The preconnect to fonts.gstatic.com makes sense since the browser will otherwise only find out about that domain after it has downloaded the stylesheet.预连接到fonts.gstatic.com是有意义的,否则浏览器只会在下载样式表后才能找到该域。 But what's the point of the preconnect to fonts.googleapis.com when the link to the stylesheet is right after it?但是,当指向样式表的链接紧随其后时,预连接到fonts.googleapis.com 的意义何在 Won't the browser process both of those at the same time?浏览器不会同时处理这两个吗?

Initiating an early connection, which includes the DNS lookup, TCP handshake, and optional TLS negotiation, allows the user agent to mask the high latency costs of establishing a connection.启动早期连接,包括 DNS 查找、TCP 握手和可选的 TLS 协商,允许用户代理掩盖建立连接的高延迟成本。 Preconnect is supported by most browsers and improves Google Fonts performance.大多数浏览器都支持预连接,并提高了 Google 字体的性能。

You can have a look to the full article https://www.cdnplanet.com/blog/faster-google-webfonts-preconnect/#:~:text=The%20preconnect%20hint,-Preconnect%20is%20one&text=Initiating%20an%20early%20connection%2C%20which,and%20improves%20Google%20Fonts%20performance .您可以查看全文https://www.cdnplanet.com/blog/faster-google-webfonts-preconnect/#:~:text=The%20preconnect%20hint,-Preconnect%20is%20one&text=Initiating% 20an%20early%20connection%2C%20which,and%20improves%20Google%20Fonts%20performance

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM