3

I am calculating TTFB (Time to First Byte) and other web vitals on a page using the web-vitals javascript library.

The flow is like this:

  1. The user, looking at a web page from server A, is clicking a button or other link, resulting in a request that goes to server A.
  2. Server A analyses the request and returns a redirect, probably 303, with the link to my page, that is on server B.
  3. The browser is redirected to my page on server B, that is loaded with the content.

In my page on server B, I measure TTFB.

Will the TTFB I measure include the time it took to get the redirect from server A?

Otto Paulsen
  • 334
  • 2
  • 11

1 Answers1

5

Yes, TTFB as measured by the Chrome UX Report (the dataset that powers Google's Web Vitals program) includes redirect times.

The definition quoted on the Chrome UX Report docs linked above is:

Time to first byte (TTFB) is a measurement used as an indication of the responsiveness of a webserver or other network resource. TTFB measures the duration from the user or client making an HTTP request to the first byte of the page being received by the client's browser. This time is made up of the socket connection time, the time taken to send the HTTP request, and the time taken to get the first byte of the page.

From Wikipedia

The reason why redirects are included in the metric is because that's what end-users experience as they wait for a page to load. Measuring only a subset of that time may paint an unrealistic picture of the UX.

Navigation Timing Level 2 image showing TTFB from the navigation start time of prompt for unload to the response start time.

Borrowing a graphic from the Navigation Timing spec, TTFB is represented by the stages in the red box above.

Rick Viscomi
  • 8,180
  • 4
  • 35
  • 50
  • By the way, would it be possible for me to measure the time from the user is making the request until the redirect is received? Or from the redirect is received until the first byte? – Otto Paulsen Sep 10 '21 at 08:15
  • 1
    Yes, the diagram in the answer shows the different Navigation Timing measurements that you can access to answer questions like these. See https://developer.mozilla.org/en-US/docs/Web/API/Navigation_timing_API for more info. – Rick Viscomi Sep 10 '21 at 16:19
  • I just tried this. I set up a server that is redirecting to my page after a 2 seconds timeout. Then I console.log the PerformanceNavigationTiming object (running locally in dev). There are many detailed timings there, however, the redirectStart, redirectEnd and redirectCount values are all 0. Maybe they are not implemented yet, and perhaps that is why they are in parentheses in the figure above. Anyway, I can calculate it pretty good using the unloadEventEnd and the fetchStart times. – Otto Paulsen Sep 15 '21 at 11:56
  • Correction to the comment above. The timing related to unload are also not implemented, it seems. – Otto Paulsen Sep 15 '21 at 12:03
  • 1
    @OttoPaulsen unload timing may be not visible due to security reasons (same origin policy etc.) - it may show implementation details of the previously opened page – Victor Sep 23 '21 at 12:12