What could cause a high TTFB on a WordPress website and how to reduce it

Your website has a high TTFB (time to the first byte) and you don’t know how to find the root cause?

If this is your case I will tell you the steps I do to find the root cause.

if the TTFB is too high, it means that the time needed by PHP to build the HTML output plus the time needed by the server to send back the output to the browser is too high.

Let’s first understand if it’s a matter of PHP or server/browser connection time.

We can check the connection time just by measuring the speed of a simple HTML file on the same server.

Because you have WordPress you will surely have the readme.html file at https://your-domain.com/readme.html or at https://your-domain.com/your-sub-folder in case WordPress is installed in a subfolder.

So measure the loading time of your readme.html file, using e.g. Pingdom or GTMetrix or whatever speed tool you like.

If your server has no connection problems, the readme.html file should load in not more than 0.4 seconds.

Perform a couple of tests, if you always see a loading time between 0.2 and 0.4, I would say that the connection is ok and we can pass to analyze the PHP performance.

As you probably already know, PHP is the programming language used by WordPress to build the final HTML output.

Before writing the HTML, PHP makes some queries to the database to fetch the needed information.

If some PHP scripts are very badly coded or ask too many slow queries to the database, the PHP parser will need a long time before making ready the HTML.

Until the HTML is not ready, the server will not send it back to the browser.

What is in WordPress that could introduce bad PHP scripts and/or too many slow database queries?

WordPress core itself, the plugins, and the theme.

Let’s exclude the first one, we are using WordPress and we are sure that the WordPress core team write good code. But we don’t completely trust all the plugins we have installed and we have some doubts also about the theme.

First, let’s see if the cause comes from the plugins, so let’s deactivate all plugins and see if the TTFB is better.

To deactivate all the plugins, just rename the plugins folder.

Now you will have 2 possibilities: the TTFB is really better, the TTFB is not a lot better.

In the first case, you have discovered that one of your plugins is guilty. In the second case, you start to suspect the theme.

Now we suppose that one of the plugins is guilty. If so you should deactivate all plugins and deactivate one plugin after the other until you don’t find guilty.

If you find it, the procedure is almost finished, then you have just to decide what you want to do with that plugin: replace it with another one having similar functionalities, write to the plugin author.

If you use Freesoul Deactivate Plugins you have a faster way to check which plugin is worsening the TTFB, and most of all without breaking the website. Watch this video to see how easy it is.

If after disabling all plugins you hadn’t found a big difference in terms of TTFB, it would be a good idea to switch to the default WordPress theme.

If with the default WordPress theme (that we consider well coded) you still notice a high TTFB, it means that neither the plugins nor the themes are causing the issue.

If you are at this point, it means that the PHP and/or MySQL performance are not good or that your database is enormous.

First, check the PHP version it’s running on your server and be sure that you have the most updated stable version. If you don’t have old plugins with compatibility issues, it’s always a good idea to have the last PHP version for both performance and security reasons.

But you are still here, your plugins are all ok, your theme is ok, you have the last PHP version, the server connection has no problems, so now? Could it really be the PHP performance? Or the database size?

Between these last two options, I would first check the database size.

If you have many products, posts, comments … your database could really be too big.

If this is your case I suggest you clean your database deleting all the posts and pages you have in the trash, spam comments, posts revisions, database tables left by removed plugins …

To accomplish it you could use e.g. the plugin Advanced Database Cleaner or similar plugins.

If after all these actions you still have a high TTFB, you could still have this kind of problems:

  • Misconfigured web server (Apache, Nginx, PHP, MySQL)
  • The origin server reached its capacity (CPU, memory, disk …)

If your website is hosted on a shared server or you simply don’t feel confident with server settings, contact the server customer service and explain all the tests you have done.

Remember that for the investigation you can always use Freesoul Deactivate Plugins.

Disabling one plugin after the other and selecting the default WordPress theme in preview mode will be a lot easier.

In any case, activating only the plugins you really need on your pages, will reduce the TTFB.

Each plugin contributes to increasing the TTFB with its database requests. You may have very light plugins that give a very low contribution. One single plugin may contribute less than 20 plugins together, but in any case, why should you load all the plugins on all the pages?

Load only what you really need.

 

Last, but not less important, you can use server cache plugins to drastically reduce the TTFB.

Serving static pages instead of dynamically built pages will drastically improve the TTFB.

It’s not a case I tell you that at the end of this blog post.

Many people do nothing to improve the TTFB but install a server cache plugin.

The TTFB must be low even without the cache. You should activate the cache only after you have optimized all the rest.

Remember that sometimes some users will see not cached pages. Moreover, if you don’t optimize keeping only what you really need, after the TTFB the browser has to load a lot of resources that the page doesn’t need. In another case, the cache will hide some problems you will not be aware of.

First optimize, then cache.

My favorite server cache plugins are:

 

I suggest you perform some tests with different cache plugins before deciding which one to use on your website. Every situation is different. The best server cache plugin for everybody doesn’t exist. It exists the best plugin for your situation.