CSS and Network Performance

栏目: CSS · 发布时间: 7年前

内容简介:Despite having been called CSS Wizardry for over a decade now, there hasn’t been a great deal of CSS-related content on this site for a while. Let me address that by combining my two favourite topics: CSS and performance.尽管已经被称为 css 魔法十多年了, 但在网站上一段时间以来, 与

Despite having been called CSS Wizardry for over a decade now, there hasn’t been a great deal of CSS-related content on this site for a while. Let me address that by combining my two favourite topics: CSS and performance.

尽管已经被称为 css 魔法十多年了, 但在网站上一段时间以来, 与css 相关的内容已经不多了。让我通过结合我最喜欢的两个主题来解决这个问题: css 和性能。

CSS is critical to rendering a page—a browser will not begin rendering until all CSS has been found, downloaded, and parsed—so it is imperative that we get it onto a user’s device as fast as we possibly can. Any delays on the Critical Path affect our Start Render and leave users looking at a blank screen.

CSS 对于渲染页面是至关重要的,浏览器只有等 CSS 全部加载和解析完全以后才会开始渲染。所有,在用户的界面上尽快的显示就是必要的,任何在关键页面的延迟都会影响开始渲染的进程,这会导致用户看到一个空白的屏幕

What’s the Big Problem

最 严重 的问题

Broadly speaking, this is why CSS is so key to performance:

从广义上讲, 这就是为什么 css 是性能的关键:

  1. A browser can’t render a page until it has built the Render Tree;
  2. the Render Tree is the combined result of the DOM and the CSSOM;
  3. the DOM is HTML plus any blocking JavaScript that needs to act upon it;
  4. the CSSOM is all CSS rules applied against the DOM;
  5. it’s easy to make JavaScript non-blocking with async and defer attributes;
  6. making CSS asynchronous is much more difficult;
  7. so a good rule of thumb to remember is that your page will only render as quickly as your slowest stylesheet .
  1. 浏览器在构建 Render Tree 前无法渲染页面
  2. Render Tree 是结合 DOM 和 CSSDOM 的结果
  3. DOM 是 HTML 加上任何对其执行不阻塞的 js
  4. CSSDOM 是适用于所有的 DOM 规则
  5. 使用异步和延迟属性很容易使 javascript 不阻塞;
  6. 要使 css 异步要困难得多;
  7. 因此, 需要记住的一个很好的经验法则是, 您的页面的渲染速度只能与加载最慢的样式表一样快

With this in mind, we need to construct the DOM and CSSOM as quickly as possible. Constructing the DOM is, for the most part, relatively fast: your first HTML response is the DOM. However, as CSS is almost always a subresource of the HTML, constructing the CSSOM usually takes a good deal longer.

出于这个目的,我们需要尽可能快的构建 DOM 和 CSSDOM。大多数情况下,构建 DOM 是很快的,第一个 HTML 响应就是 DOM,然而,CSS 总是作为 HTML 的子资源,构建 CSSDOM 通常需要花费更长的时间

In this post I want to look at how CSS can prove to be a substantial bottleneck (both in itself and for other resources) on the network, and how we can mitigate it, thus shortening the Critical Path and reducing our time to Start Render.

在这篇文章中, 我想看看 css 如何能够证明是一个实质性的瓶颈 (本身和其他资源) 上的网络, 以及我们如何可以减轻它, 从而缩短关键路径和减少我们的时间开始渲染。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

从颠覆到创新

从颠覆到创新

长江商学院 / 中国友谊出版公司 / 49.00

互联网+时代的汹涌来临,一切我们所熟知的事物都在发生改变,商业模式的剧烈变化正在席卷各行各业,所有坚硬的壁垒都将消散,所有的企业都面临着商业模式的再探索和转型,而商业模式的探索、失败、进化,甚而再回到起点,杀死自己推倒重来,不断颠覆不断创新,不断涅槃不断重生,这不仅仅是这个时代新创公司的特征,也是今天互联网领域所有存活下来的巨头们的轨迹。 本书通过11个典型的互联网企业商业模式转型案例,讲述......一起来看看 《从颠覆到创新》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换