Reduce Initial Server Response Time (TTFB) in 6 Steps
Reduce Initial Server Response Time is part of the Front-end optimization tweaks when dealing with improving website performance. However, improving how fast the response of the server where your website resides is equally essential. In this article, I will discuss how to reduce initial server response time or Time to First Byte (TTFB), its importance and provide some insights to improve this metric.
First, allow me to define some terms and explain the importance of reducing TTFB.
Waiting (TTFB) Meaning - (Time to First Byte)
Google defines TTFB as the time spent waiting for a server to deliver the initial response and includes network latency in addition to the actual time spent waiting for a resource to be received from the server.
The table below shows an example of an excellent TTFB test result for one of my client’s websites. The first five items shown are network-related tasks. The next one, ‘Waiting,’ is the actual time spent by the server to process the request. The last item shows the time it took to send the first byte of data in response to the request.
Figure 1 – TTFB Phases
Website performance testing sites recommend reducing initial server response time to provide a better experience to your website visitors.
Your Time to First Byte Is Slow
A server needs to perform many tasks in response to requests it receives. After receiving a request, it loads up the necessary files, reads through the instructions contained therein, and executes it. Poorly coded scripts significantly impact the server performance, and other factors would be inefficient database queries and the physical hardware and network resources.
Common factors affecting server response times are:
- Slow application logic
- Slow database queries
- Slow routing
- CPU resource starvation
- Memory starvation
- Slow disk speed
- High server traffic
In the latter part of this article, I will show you six ways to resolve the issues on why your time to the first byte is slow.
How to Reduce Initial Server Response Time (TTFB)
Reduce initial server response time depends on many factors and may vary based on your website setup. Google recommends keeping your server response time under 200ms. Lower is better, of course, because Google emphasizes website speed in its ranking algorithm, so:
- If your server response time is under 100ms, it’s excellent.
- Between 100ms and 200ms is considered good.
- Between 200ms and 600ms gives a warning signal so it should be improved.
- Above 600ms is too slow. You should reduce server response times.
Figure 2 – PageSpeed Insights Result (Fast TTFB)
TTFB longer than 600ms will fail these performance tests and make users wait longer to receive a response from your server and consequently a slower page load time and poorer SERP ranking.
Figure 3 – PageSpeed Insights Result (Slow TTFB)
Here are some important factors that affect the loading speed of a website:
Hosting Service: In many cases, a high server response time is caused by a bad web hosting provider, especially if you are using shared instead of dedicated hosting. If it’s dirt cheap or unreputable, you might not be getting the latest equipment. You might also be sharing bandwidth with dozens, hundreds, or even thousands of other sites.
Configurations: Your hosting service and/or server settings might not be properly optimized. Your users will be faced with slower reaction times.
Resources: If your website has a lot of pages, images, plugins, extensions, and apps, and they aren’t structured well, they will significantly slow down your website.
Caching: Proper caching allows the web browser to pull up assets from the local cache instead of making a new request to the server every single time. Optimal caching can significantly improve the page’s load speed even if it won’t directly reduce server response time.
Website Traffic: As a general rule of thumb, when more visitors make requests on your website than your server’s capacity, it will slow down the server response time. In such cases, visitors might not be able to access your website at all. If more web users are clicking around your website than it can handle, it could slow down your TTFB.
To reduce TTFB, we must first understand what happens when users visit your website.
- HTTP Request
When a user navigates to your website, TTFB starts with the HTTP request. TTFB depends on the time it takes to perform a DNS lookup—when the browser looks for the actual location of your website–the visitor’s network speed and proximity to the server, collectively called latency, and any interruptions in the network connection.
- Server Processing
Upon receiving the request, the server starts processes, runs scripts, and makes database requests.
- Sending the Response
A response consisting of the first bits of data is sent back to the browser. The speed by which this is done depends on the server’s and visitor’s network speed. Slow network connections affect TTFB.
How to Test Time to First Byte (TTFB)
Knowing your website’s initial server response time is the first step to improving TTFB. Several website speed testing tools are available free to use, such as GTmetrix, Google PageSpeed Insights, KeyCDN, and more.
Below are steps on how to use each website speed testing tool:
Go to GTmetrix, enter your website URL in the input field, and click the Test Your Site button.
Figure 4 – GTmetrix Speed Test Result
When the result shows up, click on the ‘Waterfall’ tab, then hover your mouse over the first bar of the waterfall chart. The items making up the initial server response time will be listed. In it, you will see the network-related timings and the actual waiting time where the server prepares the response it will send back.
Google PageSpeed Insights
Go to PageSpeed Insights and enter the URL you want to test, then click on the ‘Analyze’ button and wait for the result. Google emphasizes the performance of your website on mobile devices running on cellular data and presents the mobile results first. Desktop results are available on the tab next to it.
If you don’t see a warning that states “Reduce initial server response time”, your site passed the Audit and responded within 600 milliseconds.
In that case, you will see the result under the ‘Passed Audits’ section.
KeyCDN is a great tool to measure TTFB from 14 different test locations. This tool would give you an idea of how slow or fast your initial server response time is when accessed from different geographical areas.
Go to KeyCDN’s Web Performance Test tool, input your website’s URL, and click the ‘Test’ button.
Figure 5 – KeyCDN Performance Test Result
Other ways to test TTFB
There are several other online TTFB testing tools that you can use. Notable ones are Pingdom, GeekFlare’s TTFB Test, and WebPageTest, which also shows your website’s security score.
Offline test tools are also available such as TTFB For Web Developer, which runs on a Chrome browser as an extension. You can also use Chrome DevTools.
6 Ways to Reduce Server Response Times (TTFB) in WordPress
Let’s now look at the six most important ways to reduce the TTFB of your WordPress site.
1. Use a Fast Web Host
Selecting a web host with good hardware and network architecture is essential for delivering dynamic content in the fastest way possible. Poor hardware, such as those with slow hard drives, overworked CPUs, or not having enough memory to handle processes, will significantly impact serving your web pages. Heavy network traffic on low bandwidth allocation, such as those on shared hosting services or improperly configured networks resulting in bad routing, will also take its toll on how fast your server can respond to requests.
Another critical thing to consider is the server location. Select hosts that have servers as near as possible to the location of your users. If your website visitors are in Europe or the Middle East and the server is located in the US, the TTFB might be longer by half a second or more just because of the network latency due to the distance.
I did a TTFB performance test on a website without any other speed optimization and got the following results:
Figure 6 – TTFB Results on Different Hosts
As you can clearly see, using a different hosting provider can significantly impact TTFB. More on hosting comparison can be read in my Fastest Web Hosting Comparison.
2. Use Caching
Caching is probably the most significant factor for TTFB as it can reduce the duration by up to 95%. WordPress serves dynamic pages, and it is time-consuming to build the HTML to be sent to the browser on the fly. HTML caching plugins take the built page, store the cached or saved version of the page to disk or memory, and serve them on subsequent requests resulting in faster web page loading.
Another thing you can consider in selecting a fast web host is that of server-level caching. Some hosts offer LiteSpeed, Nginx, Apache/Nginx, or Varnish, allowing page caching. Sites running on PHP will also benefit if the server has opcode caching such as OpCache, Zend, or XCache. Lower TTFB can be achieved by serving pages already on cache instead of dynamically generating the pages on each request.
There are also application-level caching plugins for applications like WordPress, Drupal, or Magento. The most commonly used cache plugins for WordPress are WP-Rocket, Swift, W3 Total Cache, WP Fastest Cache, LSCache, and more.
3. Use a CDN
A Content Delivery Network (CDN) improves your server response times by delivering static content like images and scripts via a network of servers located worldwide. This system helps by having a server geographically nearest to your user deliver these files, thereby reducing network latency between your website and your users.
Not all CDNs are equally good, though. Select one with a point of presence (PoP) near your users and runs on a good network. Some also offer firewalls to block access from malicious origins.
Popular CDNs are Cloudflare CDN, RocketCDN, StackPath, and Bunny CDN.
4. Optimize your Database
Your website’s database more than likely runs on MySQL or its open-source fork MariaDB. Your web server should run the latest MySQL/MariaDB version, as these updates usually include performance and security optimizations. An updated version means new features and general improvements to existing ones. Though you may not need some of these extra features, more recent MySQL/MariaDB versions are better optimized, runs faster, and are more secure.
In time, a database can have stale content, posts revisions, trashed or deleted content, spam comments, and temporary files used by plugins. This bloat will affect processing speed and should be regularly removed to improve server response time, and automatically having these deleted regularly is preferable.
Improper database queries also have an enormous impact on server response times. Look for time-consuming slow queries and try to improve them. Sometimes, an index on a critical column would vastly cut the query processing time.
6. Keep Your System Updated
Server Configuration (PHP Version)
WordPress runs on PHP, and it needs the latest PHP version for best performance. Over 62% of all WordPress websites still run on an old version of PHP, which presents a security risk and affects the performance. Based on performance tests done by Cloudways, the average response time for PHP 7.4 is more than twice faster as PHP 5.6. So, check your server’s PHP version, and if it’s not running the latest version, I recommend you do an upgrade. WordPress recommends running PHP version 7.4 as a minimum.
Please note that PHP 5.6 and other versions before PHP 7.4 are already the end of life (EOL), are no longer maintained, and might have security issues. Be aware, though, that upgrading your PHP version might break your website due to some plugins or code that have not been updated to the latest PHP version yet, so check your website after upgrading.
If you are running WordPress version 5.2 or later, a built-in tool called Health Check shows the PHP version currently running on your server. For older versions of WordPress, you can install the plugin Display PHP Version to check the PHP version. Delete this plugin after checking your PHP version, as it will no longer be needed after the checking.
If your website is running on an old PHP version on shared hosting, just contact your hosting support to request a PHP update.
As stated before, WordPress uses the PHP engine to process the instructions required to construct the HTML sent to the browser. These instructions take time to process. PHP and database versions are essential, as mentioned above, but server hardware performance also plays a vital role in the entire process. Having a faster CPU with sufficient resources allocated by your hosting provider coupled with faster hardware will better process those files. Hence, your TTFB will be shorter.
Understanding the reasons for slow server response time and how to improve TTFB is essential to gaining a performance boost for your website.
The optimizations mentioned above would lower your TTFB and positively impact the rest of the elements. These elements comprise the Core Web Vitals, such as how quickly a page loads, how quickly a user can interact with your website, and how stable your website is when it loads in the browser.
Page Speed Optimization Course
Are you ready to learn more about advanced techniques & reduce initial server response time? Head over to my WordPress page speed optimization course and deep-dive into all the amazing knowledge of website performance optimization!
Send me your site URL, and I will personally check your site and give you a few recommendations for free.