From 1bece1192de278afcef794ef020e4c1aa06d07b0 Mon Sep 17 00:00:00 2001 From: allo Date: Tue, 19 Jul 2022 08:15:54 +0800 Subject: [PATCH 1/3] prepare markdown convertion for learn/performance --- files/zh-cn/learn/performance/css/index.html | 6 ++-- files/zh-cn/learn/performance/index.html | 32 +++++++++---------- .../perceived_performance/index.html | 16 +++++----- .../web_performance_basics/index.html | 24 +++++++------- files/zh-tw/learn/performance/index.html | 3 -- .../learn/performance/multimedia/index.html | 2 +- 6 files changed, 39 insertions(+), 44 deletions(-) diff --git a/files/zh-cn/learn/performance/css/index.html b/files/zh-cn/learn/performance/css/index.html index 17abde06d6907d..84494c175f22d7 100644 --- a/files/zh-cn/learn/performance/css/index.html +++ b/files/zh-cn/learn/performance/css/index.html @@ -3,7 +3,7 @@ slug: Learn/Performance/CSS translation_of: Learn/Performance/CSS --- -

页面在样式没有渲染完毕的情况下被绘制,在样式渲染完毕后又被刷新,这大概是很糟糕的用户体验。因此,除非浏览器知道当前不需要 该 CSS,否则 该 CSS 将阻止渲染。浏览器只会在下载 CSS 和构建 CSSOM 之后绘制页面。浏览器遵循特定的渲染路径:绘制 paint 仅在布局 layout 之后进行,布局 layout 则在创建渲染树 render tree 之后进行,创建渲染树则需要在 DOM 和 CSSOM 树解析完成后进行。为了优化 CSSOM 的构造,请删除不必要的样式,对 CSS 进行最小化,压缩和缓存,并将页面加载时不需要的 CSS 拆分为其他文件,以减少 CSS 渲染阻塞。

+

页面在样式没有渲染完毕的情况下被绘制,在样式渲染完毕后又被刷新,这大概是很糟糕的用户体验。因此,除非浏览器知道当前不需要 该 CSS,否则 该 CSS 将阻止渲染。浏览器只会在下载 CSS 和构建 CSSOM 之后绘制页面。浏览器遵循特定的渲染路径:绘制 paint 仅在布局 layout 之后进行,布局 layout 则在创建渲染树 render tree 之后进行,创建渲染树则需要在 DOM 和 CSSOM 树解析完成后进行。为了优化 CSSOM 的构造,请删除不必要的样式,对 CSS 进行最小化,压缩和缓存,并将页面加载时不需要的 CSS 拆分为其他文件,以减少 CSS 渲染阻塞。

阻塞渲染优化

@@ -17,7 +17,7 @@

阻塞渲染优化

在 GPU 上呈现动画

-

浏览器针对处理 CSS 动画和不会很好地触发重排(因此也导致重新绘制)的动画属性进行了优化。为了提高性能,可以将被动画化的节点从主线程移到 GPU 上。将导致合成的属性包括 3D transforms (transform: translateZ(), rotate3d(),etc.),animating transform 和 opacity, position: fixedwill-change,和 filter。一些元素,例如 <video>, <canvas><iframe>,也位于各自的图层上。 将元素提升为图层(也称为合成)时,动画转换属性将在 GPU 中完成,从而改善性能,尤其是在移动设备上。

+

浏览器针对处理 CSS 动画和不会很好地触发重排(因此也导致重新绘制)的动画属性进行了优化。为了提高性能,可以将被动画化的节点从主线程移到 GPU 上。将导致合成的属性包括 3D transforms (transform: translateZ(), rotate3d(),etc.),animating transform 和 opacity, position: fixedwill-change,和 filter。一些元素,例如 <video>, <canvas><iframe>,也位于各自的图层上。 将元素提升为图层(也称为合成)时,动画转换属性将在 GPU 中完成,从而改善性能,尤其是在移动设备上。

will-change 属性

@@ -39,4 +39,4 @@

font-display 属性

contain 属性

-

CSS 的 contain属性允许作者指示元素及其内容尽可能独立于文档树的其余部分。这允许浏览器针对 DOM 的有限区域而不是整个页面重新计算布局,样式,绘画,大小或它们的任意组合。

+

CSS 的 contain属性允许作者指示元素及其内容尽可能独立于文档树的其余部分。这允许浏览器针对 DOM 的有限区域而不是整个页面重新计算布局,样式,绘画,大小或它们的任意组合。

diff --git a/files/zh-cn/learn/performance/index.html b/files/zh-cn/learn/performance/index.html index c1ca0c14492fe8..0fb796156cedea 100644 --- a/files/zh-cn/learn/performance/index.html +++ b/files/zh-cn/learn/performance/index.html @@ -1,6 +1,6 @@ --- title: Web Performance -slug: learn/Performance +slug: Learn/Performance translation_of: Learn/Performance ---

{{LearnSidebar}}

@@ -16,9 +16,9 @@

学习方法

更深入进行以下主题也很有必要,这些模块包括

当你通读了这个部分之后,你或许特别想深入了解网页性能——你可以 在我们的主 MDN 网页性能章节找到更多教学,包括性能 API 的概览,测试和分析工具,以及性能瓶颈问题。

@@ -32,7 +32,7 @@

Introductory modules

This article starts the module off with a good look at what performance actually is — this includes the tools, metrics, APIs, networks, and groups of people we need to consider when thinking about performance, and how we can make performance part of our web development workflow.
How do users perceive performance?
-

More important than how fast your website is in milliseconds, is how fast your users perceive your site to be. These perceptions are impacted by actual page load time, idling, responsiveness to user interaction, and the smoothness of scrolling and other animations. In this article, we discuss the various loading metrics, animation, and responsiveness metrics, along with best practices to improve user perception, if not the actual timings.

+

More important than how fast your website is in milliseconds, is how fast your users perceive your site to be. These perceptions are impacted by actual page load time, idling, responsiveness to user interaction, and the smoothness of scrolling and other animations. In this article, we discuss the various loading metrics, animation, and responsiveness metrics, along with best practices to improve user perception, if not the actual timings.

Web performance basics
In addition to the front end components of HTML, CSS, JavaScript, and media files, there are features that can make applications slower and features that can make applications subjectively and objectively faster. There are many APIs, developer tools, best practices, and bad practices relating to web performance. Here we'll introduce many of these features ad the basic level and provide links to deeper dives to improve performance for each topic.
@@ -41,15 +41,15 @@

Introductory modules

Multimedia: images and video
The lowest hanging fruit of web performance is often media optimization. Serving different media files based on each user agent's capability, size, and pixel density is possible. Additional tips like removing audio tracks from background videos can improve performance even further. In this article we discuss the impact video, audio, and image content has on performance, and the methods to ensure that impact is as minimal as possible.
Responsive Images
-
While optimizing images is vital to high-performance media-rich user experiences, ensuring that images are sized appropriately for the devices that download them is especially important. In this article, we'll discuss the role of native browser features such as the <picture> element and the srcset attribute in efficient image delivery, and how you can use them with confidence.
+
While optimizing images is vital to high-performance media-rich user experiences, ensuring that images are sized appropriately for the devices that download them is especially important. In this article, we'll discuss the role of native browser features such as the <picture> element and the srcset attribute in efficient image delivery, and how you can use them with confidence.
Alternative media formats
-
When it comes to images and videos, there are more formats than you're likely aware of. Some of these formats can take your highly optimized media-rich pages even further by offering additional reductions in file size. In this guide we'll discuss some alternative media formats, how to use them responsibly so that non-supporting browsers don't get left out in the cold, and some advanced guidance on transcoding your existing assets to them.
+
When it comes to images and videos, there are more formats than you're likely aware of. Some of these formats can take your highly optimized media-rich pages even further by offering additional reductions in file size. In this guide we'll discuss some alternative media formats, how to use them responsibly so that non-supporting browsers don't get left out in the cold, and some advanced guidance on transcoding your existing assets to them.
CSS performance features
CSS may be a less important optimization focus for improved performance, but there are some CSS features that impact performance more than others. In this article we look at some CSS properties that impact performance and suggested ways of handling styles to ensure performance is not negatively impacted.
JavaScript performance best practices
JavaScript, when used properly, can allow for interactive and immersive web experiences — or it can significantly harm download time, render time, in-app performance, battery life, and user experience. This article outlines some JavaScript best practices that should be considered to ensure even complex content is as performant as possible.
Web font performance
-
An often overlooked aspect of performance landscape are web fonts. Web fonts are more prominent in web design than ever, yet many developers simply embed them from a third party service and think nothing of it. In this article, we'll covers methods for getting your font files as small as possible with efficient file formats and sub setting. From there, we'll go on to talk about how browsers text, and how you can use CSS and JavaScript features to ensure your fonts render quickly, and with minimal disruption to the user experience.
+
An often overlooked aspect of performance landscape are web fonts. Web fonts are more prominent in web design than ever, yet many developers simply embed them from a third party service and think nothing of it. In this article, we'll covers methods for getting your font files as small as possible with efficient file formats and sub setting. From there, we'll go on to talk about how browsers text, and how you can use CSS and JavaScript features to ensure your fonts render quickly, and with minimal disruption to the user experience.
@@ -61,9 +61,7 @@

Advanced Modules

Populating the page
-
An HTTP request is made and, hopefully, a few seconds later, the site appears. Displaying the content involves executing JavaScript, possibly modifying the DOM, calculating styles, calculating layout, and finally rendering the content, which involves painting and compositing, and can involve GPU acceleration on a separate thread.
-
Performance bottlenecks
-
+
An HTTP request is made and, hopefully, a few seconds later, the site appears. Displaying the content involves executing JavaScript, possibly modifying the DOM, calculating styles, calculating layout, and finally rendering the content, which involves painting and compositing, and can involve GPU acceleration on a separate thread.
Understanding latency

Latency is the amount of time it takes between the browser making a request for a resource, and the browser receiving back the first byte of the resource requested. This article explains what latency is, how it impacts performance, and how to measure and improve latency.

@@ -83,25 +81,25 @@

Advanced Modules

Profiling with the built-in profiler
Learn how to profile app performance with Firefox's built-in profiler.
Reading performance charts
-
Developer tools provide information on performance, memory, and network requests. Knowing how to read  waterfall charts, call trees, traces, flame charts , and allocations in your browser developer tools will help you understand waterfall and flame charts in other performance tools.
+
Developer tools provide information on performance, memory, and network requests. Knowing how to read waterfall charts, call trees, traces, flame charts , and allocations in your browser developer tools will help you understand waterfall and flame charts in other performance tools.
CSS and JavaScript animation performance
-
Animations are critical for a pleasurable user experience. This article discusses the performance differences between CSS and JavaScript-based animations.
+
Animations are critical for a pleasurable user experience. This article discusses the performance differences between CSS and JavaScript-based animations.
Analyzing JavaScript bundles
-
No doubt, JavaScript is a big part of modern web development. While you should always strive to reduce the amount of JavaScript you use in your applications, it can be difficult to know where to start. In this guide, we'll show you how to analyze your application's script bundles, so you know what you're using, as well how to detect if there are duplicated scripts between bundles in your app.
+
No doubt, JavaScript is a big part of modern web development. While you should always strive to reduce the amount of JavaScript you use in your applications, it can be difficult to know where to start. In this guide, we'll show you how to analyze your application's script bundles, so you know what you're using, as well how to detect if there are duplicated scripts between bundles in your app.
Lazy-loading JavaScript with dynamic imports
When developers hear the term "lazy loading", they immediately think of below-the-fold imagery that loads when it scrolls into the viewport. But did you know you can lazy load JavaScript as well? In this guide we'll talk about the dynamic import() statement, which is a feature in modern browsers that loads a JavaScript module on demand. Of course, since this feature isn't available everywhere, we'll also show you how you can configure your tooling to use this feature in a widely compatible fashion.
Controlling resource delivery with resource hints
-
Browsers often know better than we do when it comes to resource prioritization and delivery—but they're far from clairvoyant. Native browser features enable us to hint to the browser when it should connect to another server, or preload a resource before the browser knows it ever needs it. When used judiciously, this can make fast experience seem even faster. In this article, we cover native browser features like rel=preconnect, rel=dns-prefetch, rel=prefetch, and rel=preload, and how to use them to your advantage.
+
Browsers often know better than we do when it comes to resource prioritization and delivery—but they're far from clairvoyant. Native browser features enable us to hint to the browser when it should connect to another server, or preload a resource before the browser knows it ever needs it. When used judiciously, this can make fast experience seem even faster. In this article, we cover native browser features like rel=preconnect, rel=dns-prefetch, rel=prefetch, and rel=preload, and how to use them to your advantage.

See Also

{{LandingPageListSubpages}}

diff --git a/files/zh-cn/learn/performance/perceived_performance/index.html b/files/zh-cn/learn/performance/perceived_performance/index.html index 1321ffa78c228a..3e5b6b5f89ed51 100644 --- a/files/zh-cn/learn/performance/perceived_performance/index.html +++ b/files/zh-cn/learn/performance/perceived_performance/index.html @@ -11,7 +11,7 @@
{{PreviousMenuNext("Learn/Performance/what_is_web_performance", "Learn/Performance/Measuring_performance", "Learn/Performance")}}
-

感知性能 是用户对网站速度的感受。用户如何看待性能与任何客观统计数据一样重要,甚至更重要,但它是主观的,并且不易测量。感知性能是用户视角,而不是指标。

+

感知性能 是用户对网站速度的感受。用户如何看待性能与任何客观统计数据一样重要,甚至更重要,但它是主观的,并且不易测量。感知性能是用户视角,而不是指标。

本文简要介绍了感知性能,着眼于用户的感知,以及可以使用哪些客观工具来衡量这类主观因素。

@@ -19,7 +19,7 @@ 预备知识: - 基础计算机知识,基本软件安装, 客户端 web 技术的基础知识 + 基础计算机知识,基本软件安装客户端 web 技术的基础知识 目标 @@ -28,7 +28,7 @@ -

性能是关于用户视角的。 How fast a website feels like it's loading and rendering has a greater impact on user experience than how fast the website actually loads and renders. Even if an operation is going to take a long time (because of latency or or inavailability of the main thread), it is possible to keep the user engaged while they wait by showing a loading spinner, or a series of useful hints and tips (or jokes, or whatever else you think might be appropriate). Such an approach is much better than just showing nothing, which will make it feel like it is taking a lot longer and possibly lead to your users thinking it is broken and giving up.

+

性能是关于用户视角的。 How fast a website feels like it's loading and rendering has a greater impact on user experience than how fast the website actually loads and renders. Even if an operation is going to take a long time (because of latency or or inavailability of the main thread), it is possible to keep the user engaged while they wait by showing a loading spinner, or a series of useful hints and tips (or jokes, or whatever else you think might be appropriate). Such an approach is much better than just showing nothing, which will make it feel like it is taking a lot longer and possibly lead to your users thinking it is broken and giving up.

感知性能

@@ -36,7 +36,7 @@

感知性能

There is no unicorn metric that can measure what the user feels, but metrics are useful in guaging improvements (and regressions). Relevant measurements include first meaningful paint (FMP), largest contentful paint (LCP), time to interactive (TTI), render start, DOM interactive, and speed index.

-

First paint is reported by the browser and provides the time, in ms, of when the page starts changing; but this change can be a simple background color update or something even less noticable. It doesn’t indicate completeness and may report a time when nothing visible is painted. First Contentful Paint (FCP) reports the time when the browser first rendered anything of signifigance, be that text, foreground or background image, or a canvas or SVG; capturing the very beginning of the loading experience. But, just because there's content, doesn't mean it's useful content or that the user has content to consume. The First Meaningful Paint, or FMP, is the when content appears on the screen that is actually meaningful; which is a better metric for user-perceived loading experience, but still not ideal. Largest contentful paint (LCP) metric, definited in the Largest Contentful Paint API, reports the render time of the largest content element visible in the viewport.

+

First paint is reported by the browser and provides the time, in ms, of when the page starts changing; but this change can be a simple background color update or something even less noticable. It doesn’t indicate completeness and may report a time when nothing visible is painted. First Contentful Paint (FCP) reports the time when the browser first rendered anything of signifigance, be that text, foreground or background image, or a canvas or SVG; capturing the very beginning of the loading experience. But, just because there's content, doesn't mean it's useful content or that the user has content to consume. The First Meaningful Paint, or FMP, is the when content appears on the screen that is actually meaningful; which is a better metric for user-perceived loading experience, but still not ideal. Largest contentful paint (LCP) metric, definited in the Largest Contentful Paint API, reports the render time of the largest content element visible in the viewport.

Speed index is also used to approximate perceived performance: it measures the average time for pixels on the visible screen to be painted. It doesn't account for jitter, nor does it weight which content important to a user more highly, so it's not a perfect metric.

@@ -52,17 +52,17 @@

提升感知性能

There are tips and tricks to follow. Some of these quick tips have full articles if you want to dive deeper.

-

Displaying content, or at least some part of the page with an indication that content is loading, as quickly as possible, is essential to improving perceived performance. For example, because page render is blocked by loading and parsing CSS and JavaScript, minimizing the amount of CSS and JS that needs to be loaded on initially will have a major impact on improving perceived performance. Even though the bytes might be the same, not blocking the page from rendering makes the load feel faster.

+

Displaying content, or at least some part of the page with an indication that content is loading, as quickly as possible, is essential to improving perceived performance. For example, because page render is blocked by loading and parsing CSS and JavaScript, minimizing the amount of CSS and JS that needs to be loaded on initially will have a major impact on improving perceived performance. Even though the bytes might be the same, not blocking the page from rendering makes the load feel faster.

这里有一些技巧有助于提升性能:

最小化初始加载

-

要提升可感知性能,请最小化页面初始加载。换句话说,首先下载将实际显示的所有内容,但仅下载实际使用的内容,然后下载其余内容。因为最终要下载所有资源,所以实际上资源总量并没有改善——实际上还需要增加一些代码。但因为暂不需要的资源被延后加载了,所以用户并不会感知资源量的增加,而会感受到页面加载更快了。 

+

要提升可感知性能,请最小化页面初始加载。换句话说,首先下载将实际显示的所有内容,但仅下载实际使用的内容,然后下载其余内容。因为最终要下载所有资源,所以实际上资源总量并没有改善——实际上还需要增加一些代码。但因为暂不需要的资源被延后加载了,所以用户并不会感知资源量的增加,而会感受到页面加载更快了。

为了最大程度地减少初始加载资源,请从内容中分离交互式功能,以便优先加载初始化时所需的可见内容——文本、样式和图像。延迟加载其余资源。

-

不要加载初始页面未使用或看不到的图像或脚本,而在页面可用后延时加载,或在需要使用时按需加载。 在初始页面加载之后加载其他资源可提高感知性能。 在初始请求中加载基本数据,并仅根据需要逐步加载功能部件和数据,有助于改善低带宽和低规格硬件的体验。

+

不要加载初始页面未使用或看不到的图像或脚本,而在页面可用后延时加载,或在需要使用时按需加载。 在初始页面加载之后加载其他资源可提高感知性能。 在初始请求中加载基本数据,并仅根据需要逐步加载功能部件和数据,有助于改善低带宽和低规格硬件的体验。

此外,您应该优化需加载的资源。图片和视频应以最佳格式、压缩后的大小和正确尺寸进行投放。

@@ -72,7 +72,7 @@

防止内容跳转和其他重排

避免字体文件延迟 -

Font use can both help and harm user experience. Selecting the right fonts is an art form, and can greatly improve the user experience. Fonts can also harm user experience, especially if the fonts used need to be imported, and if the importing is not optimal, or if Comic Sans is used (kidding).  Flicker of unstyled text and missing text both harm performance.

+

Font use can both help and harm user experience. Selecting the right fonts is an art form, and can greatly improve the user experience. Fonts can also harm user experience, especially if the fonts used need to be imported, and if the importing is not optimal, or if Comic Sans is used (kidding). Flicker of unstyled text and missing text both harm performance.

Make fallback fonts the same size and weight so that when fonts load the page change is less noticeable.

diff --git a/files/zh-cn/learn/performance/web_performance_basics/index.html b/files/zh-cn/learn/performance/web_performance_basics/index.html index 94c6541c222d3c..b0690111cedd6d 100644 --- a/files/zh-cn/learn/performance/web_performance_basics/index.html +++ b/files/zh-cn/learn/performance/web_performance_basics/index.html @@ -11,34 +11,34 @@

最佳实践

  • 从学习浏览器的关键渲染路径开始。了解这些会帮助你通晓如何提升浏览器的性能。
  • 使用resource hints例如rel=preconnect, rel=dns-prefetch, rel=prefetch, and rel=preload
  • 压缩 Js 代码至最小。只为当前页面加载需要使用到的 js 代码
  • -
  • CSS性能因素 
  • +
  • CSS性能因素
  • 在你的服务器(或者 CDN)上使用 HTTP/2协议
  • -
  •  使用 CDN 托管静态资源,这样可以显著减少加载时间
  • -
  •  使用gzipBrotli 或者 Zopfli压缩您的资源
  • -
  •  图片优化(如果可以,尽可能使用 css 动画或者 svg)
  • -
  •  在超出应用视口范围的部分使用懒加载,如果你这么做了,为 SEO 制定一个后备计划(例如为 bot traffic 渲染整个页面)
  • +
  • 使用 CDN 托管静态资源,这样可以显著减少加载时间
  • +
  • 使用gzip, Brotli 或者 Zopfli压缩您的资源
  • +
  • 图片优化(如果可以,尽可能使用 css 动画或者 svg)
  • +
  • 在超出应用视口范围的部分使用懒加载,如果你这么做了,为 SEO 制定一个后备计划(例如为 bot traffic 渲染整个页面)
  • 工具

    APIs

    不该做的事(坏的实践)

    diff --git a/files/zh-tw/learn/performance/index.html b/files/zh-tw/learn/performance/index.html index 8dc477b3eb9e27..48d752747cbb62 100644 --- a/files/zh-tw/learn/performance/index.html +++ b/files/zh-tw/learn/performance/index.html @@ -78,8 +78,6 @@

    Advanced Modules

    Populating the page
    An HTTP request is made and, hopefully, a few seconds later, the site appears. Displaying the content involves executing JavaScript, possibly modifying the DOM, calculating styles, calculating layout, and finally rendering the content, which involves painting and compositing, and can involve GPU acceleration on a separate thread.
    -
    Performance bottlenecks
    -
    Understanding latency

    Latency is the amount of time it takes between the browser making a request for a resource, and the browser receiving back the first byte of the resource requested. This article explains what latency is, how it impacts performance, and how to measure and improve latency.

    @@ -111,7 +109,6 @@

    Advanced Modules

    Controlling resource delivery with resource hints
    Browsers often know better than we do when it comes to resource prioritization and delivery—but they're far from clairvoyant. Native browser features enable us to hint to the browser when it should connect to another server, or preload a resource before the browser knows it ever needs it. When used judiciously, this can make fast experience seem even faster. In this article, we cover native browser features like rel=preconnect, rel=dns-prefetch, rel=prefetch, and rel=preload, and how to use them to your advantage.
    -
    DNS-Prefetch

    See Also

    diff --git a/files/zh-tw/learn/performance/multimedia/index.html b/files/zh-tw/learn/performance/multimedia/index.html index 696a57cb5fa0cc..772d8f7d9cea04 100644 --- a/files/zh-tw/learn/performance/multimedia/index.html +++ b/files/zh-tw/learn/performance/multimedia/index.html @@ -7,7 +7,7 @@

    媒體,換句話說就是圖像跟影片,平均占了網站超過70%的下載流量。以下載的效能來考慮的話,減少媒體數量和檔案大小是一個簡單可以實現的目標。 這篇文章聚焦在優化圖像跟影片來改善網站的效能。

    -

    這是一篇進階的在 web 上優化多媒體的介紹,包含基本的原則還有技巧,想了更多的話,可以看 https://images.guide

    +

    備註: 這是一篇進階的在 web 上優化多媒體的介紹,包含基本的原則還有技巧,想了更多的話,可以看 https://images.guide

    為什麼要優化你的多媒體

    From 8eb72916a11474014a64735b7e40da3b801ab94a Mon Sep 17 00:00:00 2001 From: allo Date: Tue, 19 Jul 2022 08:17:14 +0800 Subject: [PATCH 2/3] move to .md for learn/performance --- files/zh-cn/learn/performance/css/{index.html => index.md} | 0 files/zh-cn/learn/performance/{index.html => index.md} | 0 .../performance/perceived_performance/{index.html => index.md} | 0 .../performance/web_performance_basics/{index.html => index.md} | 0 files/zh-tw/learn/performance/{index.html => index.md} | 0 files/zh-tw/learn/performance/multimedia/{index.html => index.md} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename files/zh-cn/learn/performance/css/{index.html => index.md} (100%) rename files/zh-cn/learn/performance/{index.html => index.md} (100%) rename files/zh-cn/learn/performance/perceived_performance/{index.html => index.md} (100%) rename files/zh-cn/learn/performance/web_performance_basics/{index.html => index.md} (100%) rename files/zh-tw/learn/performance/{index.html => index.md} (100%) rename files/zh-tw/learn/performance/multimedia/{index.html => index.md} (100%) diff --git a/files/zh-cn/learn/performance/css/index.html b/files/zh-cn/learn/performance/css/index.md similarity index 100% rename from files/zh-cn/learn/performance/css/index.html rename to files/zh-cn/learn/performance/css/index.md diff --git a/files/zh-cn/learn/performance/index.html b/files/zh-cn/learn/performance/index.md similarity index 100% rename from files/zh-cn/learn/performance/index.html rename to files/zh-cn/learn/performance/index.md diff --git a/files/zh-cn/learn/performance/perceived_performance/index.html b/files/zh-cn/learn/performance/perceived_performance/index.md similarity index 100% rename from files/zh-cn/learn/performance/perceived_performance/index.html rename to files/zh-cn/learn/performance/perceived_performance/index.md diff --git a/files/zh-cn/learn/performance/web_performance_basics/index.html b/files/zh-cn/learn/performance/web_performance_basics/index.md similarity index 100% rename from files/zh-cn/learn/performance/web_performance_basics/index.html rename to files/zh-cn/learn/performance/web_performance_basics/index.md diff --git a/files/zh-tw/learn/performance/index.html b/files/zh-tw/learn/performance/index.md similarity index 100% rename from files/zh-tw/learn/performance/index.html rename to files/zh-tw/learn/performance/index.md diff --git a/files/zh-tw/learn/performance/multimedia/index.html b/files/zh-tw/learn/performance/multimedia/index.md similarity index 100% rename from files/zh-tw/learn/performance/multimedia/index.html rename to files/zh-tw/learn/performance/multimedia/index.md From 22b386794828f93f39012510502f98b1ba756dbe Mon Sep 17 00:00:00 2001 From: allo Date: Tue, 19 Jul 2022 08:22:12 +0800 Subject: [PATCH 3/3] convert to markdown for learn/performance --- files/zh-cn/learn/performance/css/index.md | 42 ++-- files/zh-cn/learn/performance/index.md | 176 +++++++--------- .../perceived_performance/index.md | 128 ++++++------ .../web_performance_basics/index.md | 70 +++---- files/zh-tw/learn/performance/index.md | 190 ++++++++---------- .../learn/performance/multimedia/index.md | 150 +++++++------- 6 files changed, 357 insertions(+), 399 deletions(-) diff --git a/files/zh-cn/learn/performance/css/index.md b/files/zh-cn/learn/performance/css/index.md index 84494c175f22d7..105e9c80ff3b09 100644 --- a/files/zh-cn/learn/performance/css/index.md +++ b/files/zh-cn/learn/performance/css/index.md @@ -3,40 +3,46 @@ title: CSS performance optimization slug: Learn/Performance/CSS translation_of: Learn/Performance/CSS --- -

    页面在样式没有渲染完毕的情况下被绘制,在样式渲染完毕后又被刷新,这大概是很糟糕的用户体验。因此,除非浏览器知道当前不需要 该 CSS,否则 该 CSS 将阻止渲染。浏览器只会在下载 CSS 和构建 CSSOM 之后绘制页面。浏览器遵循特定的渲染路径:绘制 paint 仅在布局 layout 之后进行,布局 layout 则在创建渲染树 render tree 之后进行,创建渲染树则需要在 DOM 和 CSSOM 树解析完成后进行。为了优化 CSSOM 的构造,请删除不必要的样式,对 CSS 进行最小化,压缩和缓存,并将页面加载时不需要的 CSS 拆分为其他文件,以减少 CSS 渲染阻塞。

    +页面在样式没有渲染完毕的情况下被绘制,在样式渲染完毕后又被刷新,这大概是很糟糕的用户体验。因此,除非浏览器知道当前不需要 该 CSS,否则 该 CSS 将阻止渲染。浏览器只会在下载 CSS 和构建 CSSOM 之后绘制页面。浏览器遵循特定的渲染路径:绘制 paint 仅在布局 layout 之后进行,布局 layout 则在创建渲染树 render tree 之后进行,创建渲染树则需要在 DOM 和 CSSOM 树解析完成后进行。为了优化 CSSOM 的构造,请删除不必要的样式,对 CSS 进行最小化,压缩和缓存,并将页面加载时不需要的 CSS 拆分为其他文件,以减少 CSS 渲染阻塞。 -

    阻塞渲染优化

    +### 阻塞渲染优化 -

    CSS 可以使用媒体查询将样式应用在特定条件下。媒体查询对于响应式 Web 设计非常重要,可以帮助我们优化关键渲染路径。浏览器会阻塞渲染,直到它解析完全部的样式,但不会阻塞渲染它认为不会使用的样式,例如打印样式表。通过基于媒体查询将 CSS 分成多个文件,可以防止在下载未使用的 CSS 期间阻止渲染。为了创建非阻塞 CSS 链接,将不会立即使用的样式(例如打印样式)移动到单独的文件中,将 <link> 添加到 HTML 中,并添加媒体查询,在这种情况下说明它是打印样式表。

    +CSS 可以使用媒体查询将样式应用在特定条件下。媒体查询对于响应式 Web 设计非常重要,可以帮助我们优化关键渲染路径。浏览器会阻塞渲染,直到它解析完全部的样式,但不会阻塞渲染它认为不会使用的样式,例如打印样式表。通过基于媒体查询将 CSS 分成多个文件,可以防止在下载未使用的 CSS 期间阻止渲染。为了创建非阻塞 CSS 链接,将不会立即使用的样式(例如打印样式)移动到单独的文件中,将 [``](/en-US/docs/Web/HTML/Element/link) 添加到 HTML 中,并添加媒体查询,在这种情况下说明它是打印样式表。 -
    <link rel="stylesheet" href="styles.css"> <!-- blocking -->
    -<link rel="stylesheet" href="print.css" media="print"> <!-- not blocking -->
    -<link rel="stylesheet" href="mobile.css" media="screen and (max-width: 480px)"> <!-- not blocking on large screens -->
    +```html + + + +``` -

    默认情况下,浏览器假设每个指定的样式表都是阻塞渲染的。通过添加 media 属性附加媒体查询,告诉浏览器何时应用样式表。当浏览器看到一个它知道只会用于特定场景的样式表时,它仍会下载样式,但不会阻塞渲染。通过将 CSS 分成多个文件,主要的 阻塞渲染 文件(本例中为 styles.css)的大小变得更小,从而减少了渲染被阻塞的时间。

    +默认情况下,浏览器假设每个指定的样式表都是阻塞渲染的。通过添加 media 属性附加媒体查询,告诉浏览器何时应用样式表。当浏览器看到一个它知道只会用于特定场景的样式表时,它仍会下载样式,但不会阻塞渲染。通过将 CSS 分成多个文件,主要的 阻塞渲染 文件(本例中为 `styles.css`)的大小变得更小,从而减少了渲染被阻塞的时间。 -

    在 GPU 上呈现动画

    +### 在 GPU 上呈现动画 -

    浏览器针对处理 CSS 动画和不会很好地触发重排(因此也导致重新绘制)的动画属性进行了优化。为了提高性能,可以将被动画化的节点从主线程移到 GPU 上。将导致合成的属性包括 3D transforms (transform: translateZ(), rotate3d(),etc.),animating transform 和 opacity, position: fixedwill-change,和 filter。一些元素,例如 <video>, <canvas><iframe>,也位于各自的图层上。 将元素提升为图层(也称为合成)时,动画转换属性将在 GPU 中完成,从而改善性能,尤其是在移动设备上。

    +浏览器针对处理 CSS 动画和不会很好地触发重排(因此也导致重新绘制)的动画属性进行了优化。为了提高性能,可以将被动画化的节点从主线程移到 GPU 上。将导致合成的属性包括 3D transforms ([`transform: translateZ()`](/en-US/docs/Web/CSS/transform), [`rotate3d()`](/en-US/docs/Web/CSS/transform-function/rotate3d),etc.),animating transform 和 [`opacity`](/en-US/docs/Web/CSS/opacity), [`position: fixed`](/en-US/docs/Web/CSS/position),[`will-change`](/en-US/docs/Web/CSS/will-change),和 [`filter`](/en-US/docs/Web/CSS/filter)。一些元素,例如 [`