Skip to content

Commit de7486d

Browse files
committed
Refactor FPP to a similar pattern to TTLB
1 parent fb80caf commit de7486d

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

_layouts/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@
102102
//# sourceURL=sw.inline.js
103103
</script>
104104

105-
<script src=/js/obs.speedcurve.js?v=0004 type=module></script>
105+
<script src=/js/obs.speedcurve.js?v=0005 type=module></script>

js/obs.speedcurve.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,14 @@
7272
}
7373
}
7474

75-
/**
76-
* Compute new ‘First Potential Paint’ (FPP) metric. This is the time,
77-
* relative to navigation start, at which the browser finished parsing the
78-
* `<head>` and could potentially start rendering the `<body>`.
79-
*/
80-
const navEntry = performance.getEntriesByType('navigation')[0];
81-
const headEndMark = performance.getEntriesByName('HEAD_End')[0];
82-
const fpp = headEndMark.startTime - navEntry.startTime;
83-
// Assign FPP to a new `measure`.
84-
performance.measure('fpp', { start: navEntry.startTime, end: headEndMark.startTime });
75+
// First Potential Paint (FPP)
76+
if (navigation.startTime >= 0) {
77+
const headEnd = performance.getEntriesByName('HEAD_End')[0];
78+
const fpp = Math.round(headEnd.startTime - navigation.startTime);
79+
if (Number.isFinite(fpp) && fpp >= 0) {
80+
LUX.addData('fpp', fpp);
81+
}
82+
}
83+
8584

8685
})();

0 commit comments

Comments
 (0)