From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/long_tasks_api/index.html | 112 ++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 files/zh-cn/web/api/long_tasks_api/index.html (limited to 'files/zh-cn/web/api/long_tasks_api') diff --git a/files/zh-cn/web/api/long_tasks_api/index.html b/files/zh-cn/web/api/long_tasks_api/index.html new file mode 100644 index 0000000000..2593310df3 --- /dev/null +++ b/files/zh-cn/web/api/long_tasks_api/index.html @@ -0,0 +1,112 @@ +--- +title: Long Tasks API +slug: Web/API/Long_Tasks_API +translation_of: Web/API/Long_Tasks_API +--- +

{{DefaultAPISidebar("Long Tasks")}}

+ +

目的

+ +

Long Tasks,这是一个实验性API,它可以直观地告诉我们哪些任务执行耗费了50毫秒或更多时间。50毫秒这个阈值标准来源于《RAIL Model》中 "Response: process events in under 50ms" 章节。

+ +

阻塞主线程达50毫秒或以上的任务会导致以下问题:

+ + + +

概念

+ +

长任务(Long task)API使用的一些关键术语或思想。

+ +
+
+

长任务(Long task)

+
+
+ +

任何连续不间断的且主UI线程繁忙50毫秒及以上的时间区间。比如以下常规场景:

+ + + +

浏览上下文的罪魁容器

+ +

浏览上下文的罪魁容器,简称“容器”,指任务发生在其中的顶层页面(the top level page)、iframe、嵌入插槽(embed)或对象(object)。

+ +

清单(Attributions)

+ +

即执行任务的容器清单。针对没有在顶层页面容器内执行的任务,containerIdcontainerNamecontainerSrc字段可以用来提供任务源信息。

+ +

用法

+ +
var observer = new PerformanceObserver(function(list) {
+    var perfEntries = list.getEntries();
+    for (var i = 0; i < perfEntries.length; i++) {
+        // Process long task notifications:
+        // report back for analytics and monitoring
+        // ...
+    }
+});
+// register observer for long task notifications
+observer.observe({entryTypes: ["longtask"]});
+// Long script execution after this will result in queueing
+// and receiving "longtask" entries in the observer.
+
+ +

接口

+ +
+
{{domxref('PerformanceLongTaskTiming')}}
+
返回长任务实例。
+
{{domxref("TaskAttributionTiming")}}
+
返回长任务中涉及的工作及其关联的框架上下文信息。
+
+ +

规范协议

+ + + + + + + + + + + + + + +
规范协议状态备注
{{SpecName('Long Tasks')}}{{Spec2('Long Tasks')}}初始定义
+ +

浏览器兼容性

+ +

PerformanceLongTaskTiming

+ +
+ + +

{{Compat("api.PerformanceLongTaskTiming")}}

+
+ +

TaskAttributionTiming

+ +
+ + +

{{Compat("api.TaskAttributionTiming")}}

+
+ +

相关推荐

+ + -- cgit v1.2.3-54-g00ecf