Skip to content

TTFB calculation#1

Open
NK5NK5 wants to merge 1 commit intomainfrom
nicolasfaurereboot-patch-1
Open

TTFB calculation#1
NK5NK5 wants to merge 1 commit intomainfrom
nicolasfaurereboot-patch-1

Conversation

@NK5NK5
Copy link
Copy Markdown
Owner

@NK5NK5 NK5NK5 commented Feb 4, 2021

I suggest "TTFB= responseStart - navigationStart" instead of "TTFB= responseStart - requestStart".

requestStart fires after domainLookupEnd, secureConnectionStart and connectEnd as defined by the Processing Model of the PerformanceResourceTiming interface (URL: https://www.w3.org/TR/resource-timing-1/#dom-performanceresourcetiming-requeststart ). As this page defines TTFB time as including "DNS lookup and establishing the connection using a TCP handshake and SSL handshake if the request is made over https."

By the way, Google calculates the TTFB in their Chrome Extension "web vitals" as "getTTFB=responseStart"
*extract form URL: https://github.com/GoogleChrome/web-vitals/blob/master/src/getTTFB.ts
export const getTTFB = (onReport: ReportHandler) => {
const metric = initMetric('TTFB');

afterLoad(() => {
try {
// Use the NavigationTiming L2 entry if available.
const navigationEntry = performance.getEntriesByType('navigation')[0] ||
getNavigationEntryFromPerformanceTiming();

metric.value = metric.delta =
(navigationEntry as PerformanceNavigationTiming).responseStart;

metric.entries = [navigationEntry];

onReport(metric);
} catch (error) {
// Do nothing.
}
});
};


requestStart fires after domainLookupEnd, secureConnectionStart and connectEnd as defined by the Processing Model of the PerformanceResourceTiming interface (URL: https://www.w3.org/TR/resource-timing-1/#dom-performanceresourcetiming-requeststart ). As this page defines TTFB time as including "DNS lookup and establishing the connection using a TCP handshake and SSL handshake if the request is made over https." I suggest "TTFB= responseStart" or "TTFB= responseStart - navigationStart" instead of "TTFB= responseStart - requestStart".

By the way, Google calculate the TTFB in their Chrome Extension "web vitals" as  "getTTFB=responseStart"
****extract form URL: https://github.com/GoogleChrome/web-vitals/blob/master/src/getTTFB.ts***
export const getTTFB = (onReport: ReportHandler) => {
const metric = initMetric('TTFB');

afterLoad(() => {
try {
// Use the NavigationTiming L2 entry if available.
const navigationEntry = performance.getEntriesByType('navigation')[0] ||
getNavigationEntryFromPerformanceTiming();

  metric.value = metric.delta =
      (navigationEntry as PerformanceNavigationTiming).responseStart;

  metric.entries = [navigationEntry];

  onReport(metric);
} catch (error) {
  // Do nothing.
}
});
};
*****
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant