Skip to content

Instantly share code, notes, and snippets.

@despeset
Created October 16, 2013 21:19
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 despeset/7015082 to your computer and use it in GitHub Desktop.
Save despeset/7015082 to your computer and use it in GitHub Desktop.
Using requestAnimationFrame to approximate the browser's first paint time.
!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