Skip to content

Instantly share code, notes, and snippets.

@jpvincent
Last active February 11, 2022 13:05
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 jpvincent/ea0f85c1d8ad029785b956a0515ca1a4 to your computer and use it in GitHub Desktop.
Save jpvincent/ea0f85c1d8ad029785b956a0515ca1a4 to your computer and use it in GitHub Desktop.
const timings = performance.getEntriesByType('navigation')[0]
const allEntries = performance.getEntries()
const customMetrics = allEntries
.filter(entry => ['mark', 'measure'].includes(entry.entryType )) // array of PerformanceMark / PerformanceMeasure objects
.reduce((final, current) => { // make an object
final[current.entryType.toUpperCase() + ' — ' + current.name] // key name : "MARK — loadInAsync que/query_grid_webpart start"
= Math.round(
current.entryType === 'measure' ? current.duration : current.startTime
)
return final // object with key looking like this "MARK — loadInAsync que/query_grid_webpart start" and value is number of milliseconds
}, {})
// Pour Ivalua en mode DEV seulement
var jsTimer = document.getElementById('jsTimerSpan').innerText // ' +0,45'
.split(ivScope.UserNumberFormat.NumberDecimalSeparator) // [' +0', '45']
.map(Number) // [0, 45]
jsTimer = jsTimer[0] * 1000 + jsTimer[1] * 10 // 450 (en millisecondes)
const out = {
'Time To First Byte':Math.round(timings.responseStart),
'Server response time': Math.round(timings.responseStart - timings.requestStart),
// 'Input Latency' ==> plus compliqué, demande de poser des listeners en début de page
'First Paint': Math.round(allEntries.filter(entry => entry.name === 'first-paint')[0].startTime),
'jsTimer' : jsTimer,
// Visual Layout Stability ==> demande de poser des listeners en début de page
// JS blocking time ==> demande de poser des listeners en début de page
...customMetrics
}
console.table(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment