Created
December 1, 2021 08:08
-
-
Save jpnelson/958cf566e752c8d24a6273576ea6dd6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let lastHeroElement; | |
// Simplified version of our TTFMP instrumentation | |
function recursiveCheckForFirstMeaningfulPaint() { | |
const heroElement = document.getElementById("FMP-target"); | |
// To prevent against false positives during client-side route requests | |
const isSameHeroElement = lastHeroElement === heroElement; | |
const isImageHeroLoading = | |
heroElement.tagName === "IMG" && !heroElement.complete; | |
if (!heroElement || isSameHeroElement || isImageHeroLoading) { | |
requestAnimationFrame(recursiveCheckForFirstMeaningfulPaint); | |
} else { | |
requestAnimationFrame(() => { | |
lastHeroElement = heroElement; | |
performance.measure("TTFMP"); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment