Last active
March 16, 2022 06:49
-
-
Save linmic/f923a3c357f7079b01d8725d72cca7e4 to your computer and use it in GitHub Desktop.
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
// (c) Netflix UI Engineering | |
// https://www.youtube.com/watch?v=V8oTJ8OZ5S0 | |
// window.performance.timing | |
// time to Interactive (TTI) | |
// domInteractive - requestStart | |
function getTimeToInteractive() { | |
const requestStart = window.performance.timing.requestStart; | |
const domInteractive = window.performance.timing.domInteractive; | |
return domInteractive - requestStart; | |
} | |
// Resource Timing | |
function getResourceEntries() { | |
return window.performance.getEntriesByType('resource') || []; | |
} | |
function getNavigationTiming() { | |
const navs = window.performance.getEntriesByType("navigation"); | |
return navs && navs[0]; | |
} | |
function getRoundTripLength() { | |
const nav = getNavigationTiming(); | |
if (!nav) { | |
return undefined; | |
} | |
return nav.responseStart - nav.fetchStart; | |
} | |
// will output | |
const willOutput = { | |
// ... | |
name: 'https://cdn.netflix.com/myBundle.js', | |
durartion: 57.734999999, | |
transferSize: 21790 | |
// ... | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment