Skip to content

Commit aee2533

Browse files
committed
Add into to see the num of Long Tasks
1 parent c17d036 commit aee2533

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pages/Interaction/LongTask.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ To determine when long tasks happen, you can use [PerformanceObserver](https://d
55
#### Snippet
66

77
```js copy
8+
// Count and list all the Long Tasks
9+
// https://webperf-snippets.nucliweb.net
810
try {
911
const po = new PerformanceObserver((list) => {
12+
const numLongTasks = list.getEntries().length
13+
console.log(`%cNum. Long Tasks: ${numLongTasks}`,'color: #FF4E42; font-weight: bold')
1014
for (const entry of list.getEntries()) {
1115
console.table(entry.toJSON());
1216
}

pages/Loading/TTFB.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#### Snippet
66

77
```js copy
8+
// Measure the time to first byte of all the resources loaded
9+
// https://webperf-snippets.nucliweb.net
810
new PerformanceObserver((entryList) => {
911
const [pageNav] = entryList.getEntriesByType("navigation");
1012
console.log(`TTFB (ms): ${pageNav.responseStart}`);
@@ -19,21 +21,26 @@ new PerformanceObserver((entryList) => {
1921
#### Snippet
2022

2123
```js copy
24+
// Measure the time to first byte of all the resources loaded
25+
// https://webperf-snippets.nucliweb.net
2226
new PerformanceObserver((entryList) => {
2327
const entries = entryList.getEntries();
2428
const resourcesLoaded = [...entries].map((entry) => {
2529
let obj = {};
2630
// Some resources may have a responseStart value of 0, due
2731
// to the resource being cached, or a cross-origin resource
2832
// being served without a Timing-Allow-Origin header set.
33+
2934
if (entry.responseStart > 0) {
3035
obj = {
31-
"TTFB (ms)": entry.responseStart,
36+
"TTFB (ms)": +entry.responseStart.toFixed(2),
3237
Resource: entry.name,
3338
};
3439
}
35-
return obj;
36-
});
40+
return Object.keys(obj).length > 0 ? obj : undefined;
41+
})
42+
.filter((item) => item !== undefined);
43+
3744
console.table(resourcesLoaded);
3845
}).observe({
3946
type: "resource",

0 commit comments

Comments
 (0)