Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f7626c7

Browse filesBrowse files
authored
Correct TTFB breakdown
1 parent 6835e57 commit f7626c7
Copy full SHA for f7626c7

File tree

1 file changed

+13
-14
lines changed
Filter options

1 file changed

+13
-14
lines changed

‎pages/Loading/TTFB.mdx

Copy file name to clipboardExpand all lines: pages/Loading/TTFB.mdx
+13-14Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ This snippet is part of [pagespeed](https://github.com/corewebvitals/pagespeed)
3939

4040
// timing start times are relative
4141
const activationStart = pageNav.activationStart || 0;
42-
const workerStart = Math.max(pageNav.workerStart - activationStart, activationStart);
43-
const dnsStart = Math.max(pageNav.domainLookupStart - activationStart, workerStart);
44-
const tcpStart = Math.max(pageNav.connectStart - activationStart, dnsStart);
45-
const sslStart = Math.max(pageNav.secureConnectionStart - activationStart, tcpStart);
46-
const requestStart = Math.max(pageNav.requestStart - activationStart, sslStart);
47-
const responseStart = Math.max(pageNav.responseStart - activationStart, requestStart);
42+
const waitEnd = Math.max((pageNav.workerStart || pageNav.fetchStart) - activationStart, 0);
43+
const dnsStart = Math.max(pageNav.domainLookupStart - activationStart, 0);
44+
const tcpStart = Math.max(pageNav.connectStart - activationStart, 0);
45+
const sslStart = Math.max(pageNav.secureConnectionStart - activationStart, 0);
46+
const tcpEnd = Math.max(pageNav.connectEnd - activationStart, 0);
47+
const responseStart = Math.max(pageNav.responseStart - activationStart, 0);
4848

4949
// attribution based on https://www.w3.org/TR/navigation-timing-2/#processing-model
5050
// use associative array to log the results more readable
5151
let attributionArray = [];
52-
attributionArray['Redirect Time'] = {'time in ms':formatTime(workerStart - activationStart)};
53-
attributionArray['Worker and Cache Time'] = {'time in ms':formatTime(dnsStart - workerStart)};
54-
attributionArray['DNS Time'] = {'time in ms':formatTime(tcpStart - dnsStart)};
55-
attributionArray['TCP Time'] = {'time in ms':formatTime(sslStart - tcpStart)};
56-
attributionArray['SSL Time'] = {'time in ms':formatTime(requestStart - sslStart)};
57-
attributionArray['Request Time'] = {'time in ms':formatTime(responseStart - requestStart)};
58-
attributionArray['Total TTFB'] = {'time in ms':formatTime(responseStart - activationStart)};
52+
attributionArray['Redirect and Waiting duration'] = {'time in ms':formatTime(waitEnd)};
53+
attributionArray['Worker and Cache duration'] = {'time in ms':formatTime(dnsStart - waitEnd)};
54+
attributionArray['DNS duration'] = {'time in ms':formatTime(tcpStart - dnsStart)};
55+
attributionArray['TCP duration'] = {'time in ms':formatTime(sslStart - tcpStart)};
56+
attributionArray['SSL duration'] = {'time in ms':formatTime(tcpEnd - sslStart)};
57+
attributionArray['Request duration'] = {'time in ms':formatTime(responseStart - tcpEnd)};
58+
attributionArray['Total TTFB'] = {'time in ms':formatTime(responseStart)};
5959

6060
// log the results
6161
console.log('%cTime to First Byte ('+formatTime(responseStart - activationStart)+'ms)', 'color: blue; font-weight: bold;');
@@ -71,7 +71,6 @@ This snippet is part of [pagespeed](https://github.com/corewebvitals/pagespeed)
7171
})();
7272
```
7373

74-
7574
## Measure the time to first byte of all the resources loaded
7675

7776
#### Snippet

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.