What Is TTFB?
TTFB, which stands for time to first byte, is the amount of time it takes from when a client makes an HTTP request to it receiving its first byte of data from the web server. TTFB is an important aspect of website optimization since the faster the TTFB, the faster the requested resource can start being delivered to the browser.
The time to first byte is made up of three separate components.
- The time needed to send the HTTP request
- The time needed for the server to process the request
- The time needed for the server to send back the first byte of the response to the client
The TTFB for a particular resource can be visualized by using a site such as WebPageTest. For example, after running
https://www.keycdn.com through the test, we can see that the initial HTML document's TTFB took 161 ms.
What is a good TTFB?
The time to first byte can vary greatly depending on what sort of content you are serving (static vs dynamic), your server's configuration, etc. Therefore determining what is a good TTFB number is difficult to answer and is variable based on your situation. However, on average anything with a TTFB under 100 ms is fantastic. Anything between 200-500 ms is standard, between 500 ms - 1 s is less than ideal and anything greater than 1 s should likely be investigated further.
As mentioned, it should be noted that these times are average benchmarks, however do not apply to all websites. Depending on the type of content and complexity of the application it may be completely unavoidable that the TTFB is greater than 1 second.
Things that slow down your TTFB
There are a myriad of things to check in order to help determine what is causing a slow TTFB. If you are noticing that your assets are producing a long time to first byte, than it is important to investigate the issue and make any necessary changes in order to better optimize your site's performance. Common reasons why you have slower than normal TTFB can include:
- The creation of dynamic content
- Networking issues
- Poorly configured web server
- Server capacity issues (disk I/O, RAM, network bottlenecks)
- Database configuration/design
How to improve your TTFB
Knowing what areas to improve upon in order to optimize your TTFB is without a doubt very important. The next section covers a few actionable items that should be considered when moving towards improving your time to first byte.
Implement a caching mechanism
In the world of dynamic content, many processes and interactions must be carried out in order the generate a page. These interactions each take time and can consequently increase your TTFB. Implementing a caching mechanism can help minimize the load time disadvantages as it keeps a stored copy of a prebuilt page that was previously requested.
The well known WordPress CMS has many plugin options for caching content. KeyCDN's WordPress Cache Enabler plugin is an easy to use and straightforward plugin that creates a cached static HTML file on your origin server. This allows users to avoid the backend resource intensive processes, thus being able to deliver the page with a faster TTFB.
Here is an example of a website that does not have the WordPress Cache Enabler plugin installed. As can be seen the TTFB is 1.15 s which is quite high.
After enabling the WordPress Cache Enabler plugin on the same site, and implementing the advanced configuration snippet, the new TTFB is 66.72 ms. That's over a whole second improvement in the time to first byte.
Update to the latest version
Make sure to update your server stack to the latest version to take advantage of any performance updates that have been released. This applies to your web server (e.g Apache, Nginx) your server side language (e.g PHP, Ruby) and anything else that is running on your server.
Check your logs
Keep an eye on your logs mainly to track any any signs that may indicate a system is being overloaded. This can include your web server or even your database. If your website is receiving large amounts of traffic, your current web stack may not be able to properly handle the amount of requests and thus will begin producing longer TTFB's.
Being aware of your website's TTFB and how to minimize it as much as possible is a great step forward in being able to optimize your website's page speed. Keeping up to date with the latest software releases, checking up on your web server's load capacity and implementing a caching mechanism are a few ways to keep your time to first byte in check.