This is an old revision of the document!


Optimizing time to first byte

According to Wikipedia, 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.”

In short, it is a commonly used performance measurement of how long it takes for the web server to start sending data. It's often misused as a general performance metric: for example, more aggressive gzip compression might worsen your TTFB, but improve your overall page load time. It's useful as a diagnostic indicator though, and this page will go through some common reasons your TTFB might be very high.

One common reason for high TTFB is high resource usage on your server. All CPU cores might be busy, or your server might be swapping if it's running low on RAM. Some things to check for:

  • Run top: how's your CPU usage and RAM looking? Alternatively, for RAM, you can also use free -m
  • Run df -h: are any partitions out of disk space?
  • What about your bandwidth usage? You can use tools like nload to check, and your provider will likely have bandwidth graphs too.

Your TTFB may be high if your website makes very many database queries, or consists of very unoptimized application code. A common example of this is WordPress websites that use dozens of plugins. If possible, look into reducing the workload for your application. Caching may help alleviate this: consider using LiteSpeed Cache if you aren't already.

This is especially common in VPSes, where some providers severely oversell, or use old setups. You may also encounter this, for example, if your server is on very old, very slow hardware. You may need to migrate to another provider.

  • Admin
  • Last modified: 2018/11/09 15:50
  • by Erwin Venekamp