Skip to content

Instantly share code, notes, and snippets.

@xnimorz

xnimorz/fmp_2.js Secret

Created November 1, 2019 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnimorz/917a57c624a24923dee002be5edce24d to your computer and use it in GitHub Desktop.
Save xnimorz/917a57c624a24923dee002be5edce24d to your computer and use it in GitHub Desktop.
FMP 2 try
// Запланировали отрисовку
requestAnimationFrame(function() {
// кадр еще не отрисовался, но рендер три в этот момент доступно
var renderTreeFormed = performance.now();
// После этого raf кадр отрисовался
requestAnimationFrame(function() {
var fmp = performance.now();
// Если страница была неактивна — не сохраняем эти данные
if (!window.globalVars.performance.pageWasActive) {
return;
}
window.globalVars.performance.fmp.push({
renderTreeFormed: renderTreeFormed,
fmp: fmp
})
});
});
window.globalVars.performance.pageWasActive = document.visibilityState === "visible";
document.addEventListener("visibilitychange", function(e) {
if (document.visibilityState !== "visible") {
window.globalVars.performance.pageWasActive = false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment