Skip to content

Instantly share code, notes, and snippets.

@samarpanda
Last active May 17, 2019 04:37
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 samarpanda/aa6049e43f50898103e52eca8dfa5e6b to your computer and use it in GitHub Desktop.
Save samarpanda/aa6049e43f50898103e52eca8dfa5e6b to your computer and use it in GitHub Desktop.

Custom Metric using Element Timing Origin Trial

bit.ly/element-timing-origin-trial

Time To First Cat(TTFC)

Calculate time to first cat(TTFC) HTML

<img src="best_cat.jpg" elementtiming>

JS

const observer = new PerformanceObserver(list => {
  list.getEntries().forEach(function(entry){
    const navStart = performance.timing.navigationstart;
    // ttfc = navigation until image rendered
    const ttfc = entry.startTime - navStart;
    console.log(`Time To First Cat ${ttfc}`)
  });
});
observer.observe({entryTypes: ['element']});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment