@@ -17,8 +17,11 @@ async function getFileNames(dirName) {
17
17
18
18
// The resource type of all the late requests and their count are stored in this variable
19
19
let resourceTypeCountLS = { } ;
20
+ // The resource type of priority changed late requests
20
21
let resourceTypeCountPCS = { } ;
22
+ // The resource type of important late requests
21
23
let resourceTypeCountIS = { } ;
24
+ // The resource type of render blocking late requests
22
25
let resourceTypeCountRBS = { } ;
23
26
24
27
function getInitTS ( data ) {
@@ -49,6 +52,9 @@ function getSiteURL(data) {
49
52
return "" ;
50
53
}
51
54
55
+ // This function goes through the trace data to find an event with the given key and
56
+ // return its timestamp. The variable first decides whether to return the first event with
57
+ // the given name or vice versa.
52
58
function getNameValue ( key , first , data ) {
53
59
let ts = - 1 ;
54
60
@@ -91,7 +97,9 @@ function getCriticalResources(data, lcpTS) {
91
97
} ;
92
98
}
93
99
100
+ // Request ID
94
101
let currReqId ;
102
+
95
103
// Get timeline events
96
104
if (
97
105
"args" in event &&
@@ -122,6 +130,7 @@ function getCriticalResources(data, lcpTS) {
122
130
}
123
131
}
124
132
133
+ // Delete the requests which received data after LCP
125
134
for ( let rId in requests ) {
126
135
if ( requests [ rId ] [ "firstReceivedData" ] === null ) {
127
136
delete requests [ rId ] ;
@@ -141,12 +150,14 @@ function getCriticalResources(data, lcpTS) {
141
150
let maxReqStartTime ;
142
151
143
152
for ( let rId in requests ) {
153
+ // Check if the request is loaded from a cache
144
154
if ( requests [ rId ] [ "fromCache" ] ) cachedCount ++ ;
145
155
156
+ // Only process if the request is late. Here we are checking if the request was
157
+ // initiated after the end time of the initial HTML document.
146
158
if ( requests [ rId ] [ "start" ] > firstEnd ) {
147
- // Note down the min and max timestamps in the late requests
148
- // This will be used to calculate the minimum amount of time lost
149
-
159
+ // This logic is used to identify the request which is taking the longest
160
+ // time. This particular metric is not used in the report as of now.
150
161
if (
151
162
! [ "Low" , "veryLow" ] . includes ( requests [ rId ] [ "priority" ] ) &&
152
163
maxDuration <
@@ -160,14 +171,17 @@ function getCriticalResources(data, lcpTS) {
160
171
161
172
lateStartedScripts . push ( requests [ rId ] ) ;
162
173
174
+ // Check if the request priority changed
163
175
if ( requests [ rId ] [ "priorityChanged" ] ) {
164
176
priorityChangedScripts . push ( requests [ rId ] ) ;
165
177
}
166
178
179
+ // Check if the request is render blocking
167
180
if ( requests [ rId ] [ "renderBlocking" ] === "blocking" ) {
168
181
renderBlockingScripts . push ( requests [ rId ] ) ;
169
182
}
170
183
184
+ // Check if the request is important (Very High, High, Medium priority)
171
185
if ( ! [ "Low" , "veryLow" ] . includes ( requests [ rId ] [ "priority" ] ) ) {
172
186
impScripts . push ( requests [ rId ] ) ;
173
187
}
@@ -192,6 +206,8 @@ function getCriticalResources(data, lcpTS) {
192
206
} ) ;
193
207
} ) ;
194
208
209
+ // Uncomment during debugging
210
+
195
211
// console.log(`Total no. of requests: ${Object.keys(requests).length}`);
196
212
// console.log(`Total no. of cached requests: ${cachedCount}`);
197
213
// console.log(
@@ -227,6 +243,7 @@ function getCriticalResources(data, lcpTS) {
227
243
} ;
228
244
}
229
245
246
+ // Use this function to go through the timeline of a request (use it for debugging)
230
247
function printRequestTimeLine ( data , reqId ) {
231
248
// Get initial timestamp
232
249
let initTS = getInitTS ( data ) ;
@@ -276,9 +293,8 @@ async function getMetrics(fileName) {
276
293
277
294
let criticalMetrics = getCriticalResources ( data , lcpTS ) ;
278
295
279
- // printRequestTimeLine(data, "5853.56");
280
-
281
- // Debug for name property
296
+ // Debug for name property. Use the below piece of logic to identify
297
+ // different event types present in the trace data
282
298
283
299
// Group by different types of trace logs
284
300
// let names = {};
@@ -290,21 +306,6 @@ async function getMetrics(fileName) {
290
306
// names[event["name"]]++;
291
307
// });
292
308
293
- // names = Object.entries(names).sort((a, b) => -(a[1] - b[1]));
294
- // await fs.writeFile("./names.json", JSON.stringify(names, null, 4));
295
-
296
- // console.log(`Site: ${siteURL}`);
297
- // console.log(data["metadata"]["networkThrottling"]);
298
- // console.log("================================================");
299
- // console.log("First Paint Time: " + convertTSToTimeInSec(fPT) + "s");
300
- // console.log(
301
- // "First Meaningful Paint Time: " + convertTSToTimeInSec(fMPT) + "s"
302
- // );
303
- // console.log(
304
- // "Largest Contentful Paint Time: " + convertTSToTimeInSec(lCPT) + "s"
305
- // );
306
- // console.log("\n");
307
-
308
309
criticalMetrics [ "throttling" ] = data [ "metadata" ] [ "networkThrottling" ] ;
309
310
criticalMetrics [ "fPT" ] = fPT ;
310
311
criticalMetrics [ "fMPT" ] = fMPT ;
@@ -316,6 +317,7 @@ async function getMetrics(fileName) {
316
317
}
317
318
}
318
319
320
+ // This function is used to create the text for the report
319
321
function renderText ( siteURL , m ) {
320
322
let output = `URL tested: ${ siteURL } ` ;
321
323
@@ -341,8 +343,6 @@ function renderText(siteURL, m) {
341
343
Object . keys ( m . renderBlockingScripts ) . length
342
344
} \n\n`;
343
345
344
- //output += `Minimum time lost: ${m.minTimeLost}s\n\n`;
345
-
346
346
let reqInfo = {
347
347
renderBlockedReqs : {
348
348
data : m . renderBlockingScripts ,
0 commit comments