Skip to content

Instantly share code, notes, and snippets.

@linmic
Last active March 16, 2022 06:49
Show Gist options
  • Save linmic/f923a3c357f7079b01d8725d72cca7e4 to your computer and use it in GitHub Desktop.
Save linmic/f923a3c357f7079b01d8725d72cca7e4 to your computer and use it in GitHub Desktop.
// (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