Skip to content

Commit acb92d4

Browse files
committed
added missing comments
1 parent 5412e3a commit acb92d4

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

main.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ async function getFileNames(dirName) {
1717

1818
// The resource type of all the late requests and their count are stored in this variable
1919
let resourceTypeCountLS = {};
20+
// The resource type of priority changed late requests
2021
let resourceTypeCountPCS = {};
22+
// The resource type of important late requests
2123
let resourceTypeCountIS = {};
24+
// The resource type of render blocking late requests
2225
let resourceTypeCountRBS = {};
2326

2427
function getInitTS(data) {
@@ -49,6 +52,9 @@ function getSiteURL(data) {
4952
return "";
5053
}
5154

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.
5258
function getNameValue(key, first, data) {
5359
let ts = -1;
5460

@@ -91,7 +97,9 @@ function getCriticalResources(data, lcpTS) {
9197
};
9298
}
9399

100+
// Request ID
94101
let currReqId;
102+
95103
// Get timeline events
96104
if (
97105
"args" in event &&
@@ -122,6 +130,7 @@ function getCriticalResources(data, lcpTS) {
122130
}
123131
}
124132

133+
// Delete the requests which received data after LCP
125134
for (let rId in requests) {
126135
if (requests[rId]["firstReceivedData"] === null) {
127136
delete requests[rId];
@@ -141,12 +150,14 @@ function getCriticalResources(data, lcpTS) {
141150
let maxReqStartTime;
142151

143152
for (let rId in requests) {
153+
// Check if the request is loaded from a cache
144154
if (requests[rId]["fromCache"]) cachedCount++;
145155

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.
146158
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.
150161
if (
151162
!["Low", "veryLow"].includes(requests[rId]["priority"]) &&
152163
maxDuration <
@@ -160,14 +171,17 @@ function getCriticalResources(data, lcpTS) {
160171

161172
lateStartedScripts.push(requests[rId]);
162173

174+
// Check if the request priority changed
163175
if (requests[rId]["priorityChanged"]) {
164176
priorityChangedScripts.push(requests[rId]);
165177
}
166178

179+
// Check if the request is render blocking
167180
if (requests[rId]["renderBlocking"] === "blocking") {
168181
renderBlockingScripts.push(requests[rId]);
169182
}
170183

184+
// Check if the request is important (Very High, High, Medium priority)
171185
if (!["Low", "veryLow"].includes(requests[rId]["priority"])) {
172186
impScripts.push(requests[rId]);
173187
}
@@ -192,6 +206,8 @@ function getCriticalResources(data, lcpTS) {
192206
});
193207
});
194208

209+
// Uncomment during debugging
210+
195211
// console.log(`Total no. of requests: ${Object.keys(requests).length}`);
196212
// console.log(`Total no. of cached requests: ${cachedCount}`);
197213
// console.log(
@@ -227,6 +243,7 @@ function getCriticalResources(data, lcpTS) {
227243
};
228244
}
229245

246+
// Use this function to go through the timeline of a request (use it for debugging)
230247
function printRequestTimeLine(data, reqId) {
231248
// Get initial timestamp
232249
let initTS = getInitTS(data);
@@ -276,9 +293,8 @@ async function getMetrics(fileName) {
276293

277294
let criticalMetrics = getCriticalResources(data, lcpTS);
278295

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
282298

283299
// Group by different types of trace logs
284300
// let names = {};
@@ -290,21 +306,6 @@ async function getMetrics(fileName) {
290306
// names[event["name"]]++;
291307
// });
292308

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-
308309
criticalMetrics["throttling"] = data["metadata"]["networkThrottling"];
309310
criticalMetrics["fPT"] = fPT;
310311
criticalMetrics["fMPT"] = fMPT;
@@ -316,6 +317,7 @@ async function getMetrics(fileName) {
316317
}
317318
}
318319

320+
// This function is used to create the text for the report
319321
function renderText(siteURL, m) {
320322
let output = `URL tested: ${siteURL}`;
321323

@@ -341,8 +343,6 @@ function renderText(siteURL, m) {
341343
Object.keys(m.renderBlockingScripts).length
342344
}\n\n`;
343345

344-
//output += `Minimum time lost: ${m.minTimeLost}s\n\n`;
345-
346346
let reqInfo = {
347347
renderBlockedReqs: {
348348
data: m.renderBlockingScripts,

0 commit comments

Comments
 (0)