Time To First Byte: Beyond Server Response Time
smashingmagazine.com
This article is a sponsored by DebugBearLoading your website HTML quickly has a big impact on visitor experience. After all, no page content can be displayed until after the first chunk of the HTML has been loaded. Thats why the Time to First Byte (TTFB) metric is important: it measures how soon after navigation the browser starts receiving the HTML response.Generating the HTML document quickly plays a big part in minimizing TTFB delays. But actually, theres a lot more to optimizing this metric. In this article, well take a look at what else can cause poor TTFB and what you can do to fix it.What Components Make Up The Time To First Byte Metric?TTFB stands for Time to First Byte. But where does it measure from?Different tools handle this differently. Some only count the time spent sending the HTTP request and getting a response, ignoring everything else that needs to happen first before the resource can be loaded. However, when looking at Googles Core Web Vitals, TTFB starts from the time when the users start navigating to a new page. That means TTFB includes:Cross-origin redirects,Time spent connecting to the server,Same-origin redirects, andThe actual request for the HTML document.We can see an example of this in this request waterfall visualization.The server response time here is only 183 milliseconds, or about 12% of the overall TTFB metric. Half of the time is instead spent on a cross-origin redirect a separate HTTP request that returns a redirect response before we can even make the request that returns the websites HTML code. And when we make that request, most of the time is spent on establishing the server connection.Connecting to a server on the web typically takes three round trips on the network:DNS: Looking up the server IP address.TCP: Establishing a reliable connection to the server.TLS: Creating a secure encrypted connection.What Network Latency Means For Time To First ByteLets add up all the network round trips in the example above:2 server connections: 6 round trips.2 HTTP requests: 2 round trips.That means that before we even get the first response byte for our page we actually have to send data back and forth between the browser and a server eight times!Thats where network latency comes in, or network round trip time (RTT) if we look at the time it takes to send data to a server and receive a response in the browser. On a high-latency connection with a 150 millisecond RTT, making those eight round trips will take 1.2 seconds. So, even if the server always responds instantly, we cant get a TTFB lower than that number.Network latency depends a lot on the geographic distances between the visitors device and the server the browser is connecting to. You can see the impact of that in practice by running a global TTFB test on a website. Here, Ive tested a website thats hosted in Brazil. We get good TTFB scores when testing from Brazil and the US East Coast. However, visitors from Europe, Asia, or Australia wait a while for the website to load.What Content Delivery Networks Mean for Time to First ByteOne way to speed up your website is by using a Content Delivery Network (CDN). These services provide a network of globally distributed server locations. Instead of each round trip going all the way to where your web application is hosted, browsers instead connect to a nearby CDN server (called an edge node). That greatly reduces the time spent on establishing the server connection, improving your overall TTFB metric.By default, the actual HTML request still has to be sent to your web app. However, if your content isnt dynamic, you can also cache responses at the CDN edge node. That way, the request can be served entirely through the CDN instead of data traveling all across the world.If we run a TTFB test on a website that uses a CDN, we can see that each server response comes from a regional data center close to where the request was made. In many cases, we get a TTFB of under 200 milliseconds, thanks to the response already being cached at the edge node.How To Improve Time To First ByteWhat you need to do to improve your websites TTFB score depends on what its biggest contributing component is.A lot of time is spent establishing the connection: Use a global CDN.The server response is slow: Optimize your application code or cache the responseRedirects delay TTFB: Avoid chaining redirects and optimize the server returning the redirect response.Keep in mind that TTFB depends on how visitors are accessing your website. For example, if they are logged into your application, the page content probably cant be served from the cache. You may also see a spike in TTFB when running an ad campaign, as visitors are redirected through a click-tracking server.Monitor Real User Time To First ByteIf you want to get a breakdown of what TTFB looks like for different visitors on your website, you need real user monitoring. That way, you can break down how visitor location, login status, or the referrer domain impact real user experience.DebugBear can help you collect real user metrics for Time to First Byte, Google Core Web Vitals, and other page speed metrics. You can track individual TTFB components like TCP duration or redirect time and break down website performance by country, ad campaign, and more.ConclusionBy looking at everything thats involved in serving the first byte of a website to a visitor, weve seen that just reducing server response time isnt enough and often wont even be the most impactful change you can make on your website.Just because your website is fast in one location doesnt mean its fast for everyone, as website speed varies based on where the visitor is accessing your site from.Content Delivery Networks are an incredibly powerful way to improve TTFB. Even if you dont use any of their advanced features, just using their global server network saves a lot of time when establishing a server connection.
0 Commentaires ·0 Parts ·22 Vue