Created
May 19, 2015 13:49
-
-
Save weiland/178de8f8dccf460c1aad to your computer and use it in GitHub Desktop.
window.performance usable metrics
This file contains hidden or 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
let performance = window.performance; | |
let perfSupport = !!performance; | |
/** | |
* Receive Serve, DomComplete and PageLoaded timings | |
* @returns {Object} | |
*/ | |
export function laodTimes() { | |
if (!perfSupport) { | |
return; | |
} | |
let t = performance.timing; | |
let navi = performance.navigation; | |
return { | |
redirectCount: navi.redirectCount, | |
//loadType: navi.type, // 0:user action(typing, link), 1:reload, 2: history move | |
latency: t.responseEnd - t.fetchStart, | |
serverTime: t.responseEnd - t.requestStart, | |
domComplete: t.domComplete - t.responseEnd, | |
pageLoad: t.loadEventEnd - t.responseEnd | |
}; | |
} | |
// This information could be stored using sendBeacon() | |
try { | |
navigator.sendBeacon('/analytics', JSON.stringify(laodTimes())); | |
} catch {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment