Created
October 16, 2013 21:19
-
-
Save despeset/7015082 to your computer and use it in GitHub Desktop.
Using requestAnimationFrame to approximate the browser's first paint time.
This file contains 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
!function(namespace) { | |
// normalize requestAnimationFrame across user agents | |
var vendors = ['ms', 'moz', 'webkit', 'o']; | |
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { | |
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; | |
} | |
// capture first paint | |
if(window.requestAnimationFrame) | |
requestAnimationFrame(function(){ | |
namespace.firstAnimationFrameFired = new Date().getTime(); | |
}); | |
}(window); | |
// later | |
if (window.firstAnimationFrameFired && window.performance) | |
startRender = window.firstAnimationFrameFired - window.performance.timing.responseEnd; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment