大网数据广告活动
网站运营与故障问答

How much critical CSS can be inlined before there is a negative performance impact?

· 52CE 我爱测

I've heard that to avoid render-blocking issues, it's good to inline critical CSS directly in the <HEAD> tag by including the actual CSS in <STYLE> tags, and then load the rest of the CSS asynchronously. At the other hand, I read…

问题原文

原帖链接 · stckvrw · CC BY-SA 4.0

I've heard that to avoid render-blocking issues, it's good to inline critical CSS directly in the <HEAD> tag by including the actual CSS in <STYLE> tags, and then load the rest of the CSS asynchronously.

At the other hand, I read it's bad to inline too much CSS.

Is there some limit for critical CSS after which it becomes a negative performance impact?

已采纳解答

原帖链接 · Maximillian Laumeister · CC BY-SA 4.0

As of 2011, you will see the first drop in page performance after 14.6 KB has been sent. For the speediest page, all of your HTML code from the first byte up to and including the critical CSS should fit within this amount of data.

14.6 KB is the size of an HTTP server's initial TCP congestion window assuming a default TCP IW value of 10 (which was agreed on for major web browsers in RFC 6928). This 14.6KB payload represents how much data the server can send to the client before hearing acknowledgement that the data was received (aka before waiting for the first network round-trip).

If you think of the HTTP connection as a series of boat expeditions from the server to the client, 14.6 KB is when the first explorer's ship is full, and the rest of the HTML has to sit around and wait for the cargo ships.

So if the beginning of your HTML - up until the end of your critical inlined CSS - is less than 14.6 KB, that is optimal. Due to the way TCP congestion control works (doubling the amount of data sent as each burst is acknowledged), you can send 98 KB (14 KB + 28 KB + 56 KB) within 3 round-trips - so Google recommends that all above-the-fold content should be renderable with the first 98 KB of the document for mobile page speed reasons.

In short, 14.6 KB is the upper limit for critical inlined resources to fit within the first RTT. To fit within three RTTs and Google's recommendation, the cutoff is 98 KB.

This answer applies to HTTP/1.1 and HTTP/2, as they are both TCP-based protocols. This answer does not apply to HTTP/3, as it is a UDP-based protocol with its own inbuilt ramp-up strategy that I believe may be different than the strategy used by TCP.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。