aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/learn/performance
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/learn/performance
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/learn/performance')
-rw-r--r--files/zh-cn/learn/performance/css/index.html44
-rw-r--r--files/zh-cn/learn/performance/index.html107
-rw-r--r--files/zh-cn/learn/performance/web_performance_basics/index.html44
-rw-r--r--files/zh-cn/learn/performance/感知性能/index.html109
4 files changed, 304 insertions, 0 deletions
diff --git a/files/zh-cn/learn/performance/css/index.html b/files/zh-cn/learn/performance/css/index.html
new file mode 100644
index 0000000000..e122e198be
--- /dev/null
+++ b/files/zh-cn/learn/performance/css/index.html
@@ -0,0 +1,44 @@
+---
+title: CSS performance optimization
+slug: Learn/Performance/CSS
+translation_of: Learn/Performance/CSS
+---
+<p>{{draft}}</p>
+
+<p>页面在样式没有渲染完毕的情况下被绘制,在样式渲染完毕后又被刷新,这大概是很糟糕的用户体验。因此,除非浏览器知道当前不需要 该 CSS,否则 该 CSS将阻止渲染。浏览器只会在下载 CSS 和构建 CSSOM之后绘制页面。浏览器遵循特定的渲染路径:绘制 paint 仅在布局 layout之后进行,布局 layout 则在创建渲染树 render tree 之后进行,创建渲染树则需要在DOM和CSSOM 树解析完成后进行。为了优化CSSOM的构造,请删除不必要的样式,对 CSS 进行最小化,压缩和缓存,并将页面加载时不需要的CSS拆分为其他文件,以减少CSS渲染阻塞。</p>
+
+<h3 id="阻塞渲染优化">阻塞渲染优化</h3>
+
+<p>CSS 可以使用媒体查询将样式应用在特定条件下。媒体查询对于响应式 Web 设计非常重要,可以帮助我们优化关键渲染路径。浏览器会阻塞渲染,直到它解析完全部的样式,但不会阻塞渲染它认为不会使用的样式,例如打印样式表。通过基于媒体查询将CSS分成多个文件,可以防止在下载未使用的CSS期间阻止渲染。为了创建非阻塞 CSS 链接,将不会立即使用的样式(例如打印样式)移动到单独的文件中,将 <code><a href="/en-US/docs/Web/HTML/Element/link">&lt;link&gt;</a></code> 添加到 HTML 中,并添加媒体查询,在这种情况下说明它是打印样式表。</p>
+
+<pre class="brush: html">&lt;link rel="stylesheet" href="styles.css"&gt; &lt;!-- blocking --&gt;
+&lt;link rel="stylesheet" href="print.css" media="print"&gt; &lt;!-- not blocking --&gt;
+&lt;link rel="stylesheet" href="mobile.css" media="screen and (max-width: 480px)"&gt; &lt;!-- not blocking on large screens --&gt;</pre>
+
+<p>默认情况下,浏览器假设每个指定的样式表都是阻塞渲染的。通过添加 media属性附加媒体查询,告诉浏览器何时应用样式表。当浏览器看到一个它知道只会用于特定场景的样式表时,它仍会下载样式,但不会阻塞渲染。通过将 CSS 分成多个文件,主要的 阻塞渲染 文件(本例中为 <code>styles.css</code>)的大小变得更小,从而减少了渲染被阻塞的时间。</p>
+
+<h3 id="在GPU_上呈现动画">在GPU 上呈现动画</h3>
+
+<p>浏览器针对处理CSS动画和不会很好地触发重排(因此也导致重新绘制)的动画属性进行了优化。为了提高性能,可以将被动画化的节点从主线程移到GPU上。将导致合成的属性包括 3D transforms (<code><a href="/en-US/docs/Web/CSS/transform">transform: translateZ()</a></code>, <code><a href="/en-US/docs/Web/CSS/transform-function/rotate3d">rotate3d()</a></code>,etc.),animating transform 和 <code><a href="/en-US/docs/Web/CSS/opacity">opacity</a></code>, <code><a href="/en-US/docs/Web/CSS/position">position: fixed</a></code>,<code><a href="/en-US/docs/Web/CSS/will-change">will-change</a></code>,和 <code><a href="/en-US/docs/Web/CSS/filter">filter</a></code>。一些元素,例如 <code><a href="/en-US/docs/Web/HTML/Element/video">&lt;video&gt;</a></code>, <code><a href="/en-US/docs/Web/HTML/Element/canvas">&lt;canvas&gt;</a></code> 和 <code><a href="/en-US/docs/Web/HTML/Element/iframe">&lt;iframe&gt;</a></code>,也位于各自的图层上。 将元素提升为图层(也称为合成)时,动画转换属性将在GPU中完成,从而改善性能,尤其是在移动设备上。</p>
+
+<h3 id="will-change_属性"><code>will-change</code> 属性</h3>
+
+<p>CSS <a href="/en-US/docs/Web/CSS/will-change"><code>will-change</code></a> 属性告诉浏览器元素的哪些属性需要修改,使浏览器能够在元素实际更改之前设置优化,通过在实际更改前执行耗时的工作以提升性能。</p>
+
+<pre class="brush: css">will-change: opacity, transform;</pre>
+
+<h3 id="font-display_属性"><code>font-display</code> 属性</h3>
+
+<p>根据 <a href="/en-US/docs/Web/CSS/@font-face">@font-face</a> 规则,<a href="/en-US/docs/Web/CSS/@font-face/font-display">font-display</a> 属性定义了浏览器如何加载和显示字体文件,允许文本在字体加载或加载失败时显示回退字体。可以通过依靠折中无样式文本闪现使文本可见替代白屏来提高性能。</p>
+
+<pre class="brush: css">@font-face {
+ font-family: someFont;
+ src: url(/path/to/fonts/someFont.woff) format('woff');
+ font-weight: 400;
+ font-style: normal;
+ font-display: fallback;
+}</pre>
+
+<h3 id="contain_属性"><code>contain</code> 属性</h3>
+
+<p>CSS的 <code>contain</code>属性允许作者指示元素及其内容尽可能独立于文档树的其余部分。 这允许浏览器针对DOM的有限区域而不是整个页面重新计算布局,样式,绘画,大小或它们的任意组合。</p>
diff --git a/files/zh-cn/learn/performance/index.html b/files/zh-cn/learn/performance/index.html
new file mode 100644
index 0000000000..1d6e2b8c72
--- /dev/null
+++ b/files/zh-cn/learn/performance/index.html
@@ -0,0 +1,107 @@
+---
+title: Web Performance
+slug: learn/Performance
+translation_of: Learn/Performance
+---
+<h2 id="LearnSidebardraft">{{LearnSidebar}}{{draft}}</h2>
+
+<p class="summary">构建一个网站需要HTML、CSS和JavaScript。为了构建人们需要的、能吸引和留住用户的网站和应用,你需要创建一个良好的用户体验。良好用户体验的一部分是确保内容能够快速加载并响应用户交互。这就是所谓的<strong>web性能</strong>,在这个模块中,你将会学到构建性能良好的网站所需要的知识。</p>
+
+<p>给初学者的学习材料的剩下部分主要关注于如何尽量提高性能和易用性等网络体验。但是,也需要特别关注这些话题,确保你熟悉他们。</p>
+
+<h2 id="学习方法">学习方法</h2>
+
+<p>虽然了解HTML,CSS和Javascript是实现许多网页性能提升建议的必要条件,但了解如何构建应用却不是理解和衡量网页性能的必要先决条件。即便如此我们仍建议在通读此模块之前,你至少要过一遍我们的网页编程入门模块,对网页发展有一个基本认识。</p>
+
+<p>更深入进行以下主题也很有必要,这些模块包括</p>
+
+<ul>
+ <li>HTML入门 </li>
+ <li>CSS初步 </li>
+ <li>Javascript初步 </li>
+</ul>
+
+<p>当你通读了这个部分之后,你或许特别想深入了解网页性能——你可以 在我们的主MDN网页性能章节找到更多教学,包括性能API的概览,测试和分析工具 ,以及性能瓶颈问题。</p>
+
+<h2 id="Introductory_modules">Introductory modules</h2>
+
+<p>This topic contains the following modules, in a suggested order for working through them. You should definitely start with the first one.</p>
+
+<dl>
+ <dt><a href="/en-US/docs/Learn/Performance/What_is_performance">What is web performance?</a></dt>
+ <dd>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.</dd>
+ <dt><a href="/en-US/docs/Learn/Performance/Perceived_performance">How do users perceive performance?</a></dt>
+ <dd>
+ <p>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 p<span>age 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.</span></p>
+ </dd>
+ <dt><a href="/en-US/docs/Learn/Performance/Basics">Web performance basics</a></dt>
+ <dd>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.</dd>
+ <dt><a href="/en-US/docs/Learn/Performance/HTML">HTML performance features</a></dt>
+ <dd>Some attributes and the source order of your mark-up can impact the performance or your website. By minimizing the number of DOM nodes, making sure the best order and attributes are used for including content such as styles, scripts, media, and third-party scripts, you can drastically improve the user experience. This article looks in detail at how HTML can be used to ensure maximum performance.</dd>
+ <dt><a href="/en-US/docs/Learn/Performance/Multimedia">Multimedia: images and video</a></dt>
+ <dd>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.</dd>
+ <dt>Responsive Images</dt>
+ <dd>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 &lt;picture&gt; element and the srcset attribute in efficient image delivery, and how you can use them with confidence.</dd>
+ <dt>Alternative media formats</dt>
+ <dd>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.</dd>
+ <dt><a href="/en-US/docs/Learn/Performance/CSS">CSS performance features</a></dt>
+ <dd>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.</dd>
+ <dt><a href="/en-US/docs/Learn/Performance/JavaScript">JavaScript performance best practices</a></dt>
+ <dd>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.</dd>
+ <dt>Web font performance</dt>
+ <dd>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.</dd>
+</dl>
+
+<dl>
+ <dt><a href="/en-US/docs/Learn/Performance/Mobile">Mobile performance</a></dt>
+ <dd>With web access on mobile devices being so popular, and all mobile platforms having fully-fledged web browsers, but possibly limited bandwidth, CPU and battery life, it is important to consider the performance of your web content on these platforms. This article looks at mobile-specific performance considerations.</dd>
+</dl>
+
+<h2 id="Advanced_Modules">Advanced Modules</h2>
+
+<dl>
+ <dt>Populating the page</dt>
+ <dd>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.</dd>
+ <dt>Performance bottlenecks</dt>
+ <dd></dd>
+ <dt><a href="/en-US/docs/Learn/Performance/Latency">Understanding latency</a></dt>
+ <dd>
+ <p>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.</p>
+ </dd>
+ <dt>Understanding bandwidth</dt>
+ <dd>
+ <p>Bandwidth is the amount of data (measured in Mbps or Kbps) that can be sent per second. This article explains the role of bandwidth in media-rich internet applications, how it can be measured, and how you can optimize applications to make the best use of available bandwidth.</p>
+ </dd>
+ <dt>HTTP/2 and you</dt>
+ <dd>
+ <p>The transport layer—that is, HTTP—is utterly essential to the functioning of the web, and it has only been relatively recently that it has seen a major update in the form of HTTP/2. Out of the box, HTTP/2 provides many performance improvements and advantages over its predecessor, but it also changes the landscape. In this article, you'll learn what HTTP/2 does for you, and how to fine-tune your application to make it do go even further.</p>
+ </dd>
+ <dt>The role of TLS in performance</dt>
+ <dd>
+ <p>TLS—or HTTPS as we tend to call it—is crucial in creating secure and safe user experiences. While hardware has reduced the negative impacts TLS has had on server performance, it's still represents a substantial slice of the time we spend waiting for browsers to connect to servers. This article explains the TLS handshake process, and offers some tips for reducing this time, such as OCSP stapling, HSTS preload headers, and the potential role of resource hints in masking TLS latency for third parties.</p>
+ </dd>
+ <dt><a href="/en-US/docs/Performance/Profiling_with_the_Built-in_Profiler">Profiling with the built-in profiler</a></dt>
+ <dd>Learn how to profile app performance with Firefox's built-in profiler.</dd>
+ <dt>Reading performance charts</dt>
+ <dd>Developer tools provide information on performance, memory, and network requests. Knowing how to read  <a href="https://developer.mozilla.org/en-US/docs/Tools/Performance/Waterfall">waterfall</a> charts, <a href="https://developer.mozilla.org/en-US/docs/Tools/Performance/Call_Tree">call trees</a>, traces, <a href="https://developer.mozilla.org/en-US/docs/Tools/Performance/Flame_Chart">flame charts</a> , and <a href="https://developer.mozilla.org/en-US/docs/Tools/Performance/Allocations">allocations</a> in your browser developer tools will help you understand waterfall and flame charts in other performance tools.</dd>
+ <dt><a href="/en-US/Apps/Build/Performance/CSS_JavaScript_animation_performance">CSS and JavaScript animation performance</a></dt>
+ <dd>Animations are critical for a pleasurable user experience. This article discusses the performance differences between CSS and JavaScript-based animations.</dd>
+ <dt>Analyzing JavaScript bundles</dt>
+ <dd>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 <em>what</em> you're using, as well how to detect if there are duplicated scripts between bundles in your app.</dd>
+ <dt>Lazy-loading JavaScript with dynamic imports</dt>
+ <dd>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.</dd>
+</dl>
+
+<dl>
+ <dt>Controlling resource delivery with resource hints</dt>
+ <dd>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.</dd>
+</dl>
+
+<h2 id="See_Also">See Also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/Performance/Mobile_performance_checklist">Mobile performance checklist</a></li>
+ <li><a href="/en-US/docs/Web/Apps/Fundamentals/Performance/Optimizing_startup_performance">Optimizing Startup Performance</a><a href="/en-US/docs/Web/Apps/Fundamentals/Performance/Optimizing_startup_performance"> </a></li>
+</ul>
+
+<p>{{LandingPageListSubpages}}</p>
diff --git a/files/zh-cn/learn/performance/web_performance_basics/index.html b/files/zh-cn/learn/performance/web_performance_basics/index.html
new file mode 100644
index 0000000000..4689bfa18a
--- /dev/null
+++ b/files/zh-cn/learn/performance/web_performance_basics/index.html
@@ -0,0 +1,44 @@
+---
+title: Web performance basics
+slug: learn/Performance/Web_Performance_Basics
+translation_of: Learn/Performance/Web_Performance_Basics
+---
+<p>有很多的<a href="https://developers.google.com/web/fundamentals/performance/why-performance-matters/">理由</a>告诉你为什么你的网站需要尽可能好的性能。下面是关于最佳实践,工具,API以及链接的简明介绍,它为每个主题提供了更多的信息。意识到对用户来说什么是真正重要的也至关重要,他可能不是绝对意义上的时间而是<a href="https://developer.mozilla.org/en-US/docs/Learn/Performance/perceived_performance">用户感知的时间</a>。</p>
+
+<h4 id="最佳实践">最佳实践</h4>
+
+<ul>
+ <li>从学习浏览器的<a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Critical_rendering_path">关键渲染路径</a>开始。了解这些会帮助你通晓如何提升浏览器的性能。</li>
+ <li>使用<a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Controlling_resource_delivery_with_resource_hints">resource hints</a>例如<code>rel=preconnect, rel=dns-prefetch, rel=prefetch, and rel=preload</code></li>
+ <li>压缩Js代码至<a href="https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4">最小</a>。只为当前页面加载需要使用到的js代码</li>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Learn/Performance/CSS_performance">CSS</a>性能因素 </li>
+ <li>在你的服务器(或者CDN)上使用 <a href="https://developer.mozilla.org/en-US/docs/Learn/Performance/HTTP2">HTTP/2</a>协议</li>
+ <li> 使用CDN托管静态资源,这样可以显著减少加载时间</li>
+ <li> 使用<a href="https://www.gnu.org/software/gzip/" rel="nofollow noopener">gzip</a>, <a href="https://github.com/google/brotli" rel="nofollow noopener">Brotli</a> 或者 <a href="https://github.com/google/zopfli" rel="nofollow noopener">Zopfli</a>压缩您的资源</li>
+ <li> 图片优化(如果可以,尽可能使用css动画或者svg)</li>
+ <li> 在超出应用视口范围的部分使用懒加载,如果你这么做了,为SEO制定一个后备计划(例如为bot traffic 渲染整个页面)</li>
+</ul>
+
+<h4 id="工具">工具</h4>
+
+<ul>
+ <li>学习使用<a href="https://developer.mozilla.org/en-US/docs/Tools/Performance">Firefox Dev Tools</a>来分析您的网站。</li>
+ <li><a href="https://developers.google.com/speed/docs/insights/v5/about">Pagespeed Insights</a> 可以分析您的页面并且给出一些通用的建议来提升网站性能。</li>
+ <li><a href="https://developers.google.com/web/tools/lighthouse/">Lighthouse</a> 可以给您一份有关您网站的包括性能,SEO和可访问性等多个方面的详细分类。</li>
+ <li>使用 <a href="http://webpagetest.org/">Webpagetest.org</a>检测页面在不同真实设备类型和地点时候的速度。trics.</li>
+ <li>定义一个 绩效预算<a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Performance_budget"> </a>(<a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Performance_budget">performance budget</a>)。</li>
+</ul>
+
+<h4 id="APIs">APIs</h4>
+
+<ul>
+ <li>收集用户指标通过 <a href="https://github.com/akamai/boomerang">https://github.com/akamai/boomerang</a> 。</li>
+ <li>或者通过<a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/performance">window.performance.timing</a> 直接收集。</li>
+</ul>
+
+<h4 id="不该做的事(坏的实践)">不该做的事(坏的实践)</h4>
+
+<ul>
+ <li>  将任何东西都下载下来</li>
+ <li>  使用未经压缩的媒体文件</li>
+</ul>
diff --git a/files/zh-cn/learn/performance/感知性能/index.html b/files/zh-cn/learn/performance/感知性能/index.html
new file mode 100644
index 0000000000..3740a4c62c
--- /dev/null
+++ b/files/zh-cn/learn/performance/感知性能/index.html
@@ -0,0 +1,109 @@
+---
+title: 感知性能
+slug: learn/Performance/感知性能
+tags:
+ - Web 性能
+ - 感知性能
+translation_of: Learn/Performance/perceived_performance
+---
+<div>{{LearnSidebar}}</div>
+
+<div>{{PreviousMenuNext("Learn/Performance/what_is_web_performance", "Learn/Performance/Measuring_performance", "Learn/Performance")}}</div>
+
+<p><span class="seoSummary"><strong><a href="/zh-CN/docs/Glossary/Perceived_performance">感知性能</a></strong> 是用户对网站速度的感受。</span> 用户如何看待性能与任何客观统计数据一样重要,甚至更重要,但它是主观的,并且不易测量。感知性能是用户视角,而不是指标。</p>
+
+<p>本文简要介绍了感知性能,着眼于用户的感知,以及可以使用哪些客观工具来衡量这类主观因素。</p>
+
+<table class="learn-box standard-table">
+ <tbody>
+ <tr>
+ <th scope="row">预备知识:</th>
+ <td>基础计算机知识,<a href="https://developer.mozilla.org/en-US/Learn/Getting_started_with_the_web/Installing_basic_software">基本软件安装</a>, <a href="/en-US/docs/Learn/Getting_started_with_the_web">客户端 web 技术</a>的基础知识</td>
+ </tr>
+ <tr>
+ <th scope="row">目标</th>
+ <td>基本了解用户对Web性能的看法。</td>
+ </tr>
+ </tbody>
+</table>
+
+<p>性能是关于用户视角的。 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 <a href="/en-US/docs/Glossary/Main_thread">main thread</a>), 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.</p>
+
+<h2 id="感知性能">感知性能</h2>
+
+<p>The perception of how fast your site loads and how responsive feels to user interaction is vitally important; even more important that actual download time but difficult to quantify. There are areas of your site that you may not be able to make faster, but you can make it <em>feel</em> faster even if the metrics discussed in the othser sections can't be improved.</p>
+
+<p>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.</p>
+
+<p><strong><a href="/en-US/docs/Glossary/First_paint">First paint </a></strong>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. <strong><a href="/en-US/docs/Glossary/First_contentful_paint">First Contentful Paint</a> (FCP) </strong>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 <strong><a href="/en-US/docs/Glossary/first_meaningful_paint">First Meaningful Paint</a></strong>, 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. <strong>Largest contentful paint (LCP)</strong> metric, definited in the <a href="https://wicg.github.io/largest-contentful-paint/">Largest Contentful Paint API</a>, reports the render time of the largest content element visible in the viewport.</p>
+
+<p><strong><a href="/en-US/docs/Glossary/Speed_index">Speed index</a></strong> 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.</p>
+
+<p>These metrics have to do with initial load and render. It is also important to ensure the site feels fast once the user begins interacting with it. For this, <strong><a href="/en-US/docs/Glossary/Time_to_interactive">time to interactive</a></strong>, is a good metric; it is the moment when the last <a href="/en-US/docs/Glossary/Long_task">long task </a>of the load process finishes and the UI is available for user interaction with delay.</p>
+
+<p>UI lack or responsiveness and jank both harm perceived performance. Even though a task may take a long time, though, there are ways to make it seem faster. There are several tips to improving perceived performance.</p>
+
+<h3 id="提升感知性能">提升感知性能</h3>
+
+<p>Understanding networking, how the browser works, user perception of time, etc., can help you better understand how to improve the user interaction. However, you don't have to know the ins and outs of how everything, including how the human mind works, to improve the perception of speed.</p>
+
+<p>How fast or slow something feels like it's taking depends a lot on whether the user is actively or passively waiting for this thing to happen. Waits can have an active and passive phase. When the user is active - moving the mouse, thinking, being entertainted, they are in an active phase. The passive phase occurs when the user is passively waiting, like staring at a monochrome screen. If both the passive and active waits time were objectively equal, users would estimate that the passive waiting period was longer than the active. If a load, render, or response time can not be objectively minimized any further, turning the wait into an active wait instead of a passive wait can make it feel faster.</p>
+
+<p>There are tips and tricks to follow. Some of these quick tips have full articles if you want to dive deeper.</p>
+
+<p>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 <em>feel</em> faster.</p>
+
+<p>这里有一些技巧有助于提升性能:</p>
+
+<h3 id="最小化初始加载">最小化初始加载</h3>
+
+<p>要提升可感知性能,请最小化页面初始加载。 换句话说,首先下载将实际显示的所有内容,但仅下载实际使用的内容,然后下载其余内容。 因为最终要下载所有资源,所以实际上资源总量并没有改善——实际上还需要增加一些代码。但因为暂不需要的资源被延后加载了,所以用户并不会感知资源量的增加,而会感受到页面加载更快了。 </p>
+
+<p>为了最大程度地<a href="https://onilab.com/blog/perceived-performance-vs-actual-load-time-5-secrets-of-lightning-fast-magento-store/">减少初始加载资源</a>,请从内容中分离交互式功能,以便优先加载初始化时所需的可见内容——文本、样式和图像。 延迟加载其余资源。</p>
+
+<p>不要加载初始页面未使用或看不到的图像或脚本,而在页面可用后延时加载,或在需要使用时按需加载。 在初始页面加载之后加载其他资源可提高感知性能。 在初始请求中加载基本数据,并仅根据需要逐步加载功能部件和数据,有助于改善低带宽和低规格硬件的体验。</p>
+
+<p>此外,您应该优化需加载的资源。 图片和视频应以最佳格式、压缩后的大小和正确尺寸进行投放。</p>
+
+<h3 id="防止内容跳转和其他重排">防止内容跳转和其他重排</h3>
+
+<p>Images or other assets causing content to be pushed down or jump to a different location, like the loading of third party advertisements, can make the page feel like it is still loading and is bad for perceived performance. Content reflowing is especially bad for user experience when not initiated by user interaction. If some assets are going to be slower to load than others, with elements loading after other content has already been painted to the screen, plan ahead and leave space in the layout for them so that content doesn't jump or resize, especially after the site has become interactive.</p>
+
+<h3 id="避免字体文件延迟">避免字体文件延迟</h3>
+
+<p>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.</p>
+
+<p>Make fallback fonts the same size and weight so that when fonts load the page change is less noticeable.</p>
+
+<h3 id="交互类元素是可交互的">交互类元素是可交互的</h3>
+
+<p>Make sure visible interactive elements are always interactive and responsive. If input elements are visible, the user should be able to interact with them without a lag. Users feel that something is laggy when they take more than 50ms to react. They feel that a page is janky when content repaints slower than 16.67ms (or 60 frames per second) or repaints at uneven intervals.</p>
+
+<p>Make things like type-ahead a progressive enhancement: use css to display input modal, JS to add typeahead/autocomplete as it is available</p>
+
+<h3 id="使任务启动器显得更具交互性">使任务启动器显得更具交互性</h3>
+
+<p>在按下按键而不是等待按键弹起时发出请求,可以使感知的内容加载减少200毫秒。在 KEYUP 后添加一个有趣但不显眼的200毫秒动画,甚至可以再降低200毫秒的加载感知。 您并没有节省400毫秒的时间,但是用户直到真正等待内容时,才感觉到他们在等待内容。</p>
+
+<h2 id="总结">总结</h2>
+
+<p>By turning as much of the download, render and wait time into active phases and reducing any passive waiting, even if the objective measurements stay the same, the user will feel like the content downloaded, rendered, and responded more quickly. Now that we know what we should be speeding up, let's take a look at some metrics and learn how we can measure these events.</p>
+
+<p>{{PreviousMenuNext("Learn/Performance/what_is_web_performance", "Learn/Performance/Measuring_performance", "Learn/Performance")}}</p>
+
+<h2 id="In_this_module">In this module</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Learn/Performance/why_web_performance">The "why" of web performance</a></li>
+ <li><a href="/en-US/docs/Learn/Performance/What_is_web_performance">What is web performance?</a></li>
+ <li><a href="/en-US/docs/Learn/Performance/Perceived_performance">How do users perceive performance?</a></li>
+ <li><a href="/en-US/docs/Learn/Performance/Measuring_performance">Measuring performance</a></li>
+ <li><a href="/en-US/docs/Learn/Performance/Multimedia">Multimedia: images</a></li>
+ <li><a href="/en-US/docs/Learn/Performance/video">Multimedia: video</a></li>
+ <li><a href="/en-US/docs/Learn/Performance/JavaScript">JavaScript performance best practices</a>.</li>
+ <li><a href="/en-US/docs/Learn/Performance/HTML">HTML performance features</a></li>
+ <li><a href="/en-US/docs/Learn/Performance/CSS">CSS performance features</a></li>
+ <li><a href="/en-US/docs/Learn/Performance/Fonts">Fonts and performance</a></li>
+ <li><a href="/en-US/docs/Learn/Performance/Mobile">Mobile performance</a></li>
+ <li><a href="/en-US/docs/Learn/Performance/business_case_for_performance">Focusing on performance</a></li>
+</ul>