1. Home
  2. How to Reduce admin-ajax.php Slow Load Times in WordPress

How to Reduce admin-ajax.php Slow Load Times in WordPress

Website performance is a critical subject for any site owner. Performance issues can affect users’ experience and potentially reduce SEO ranking. As Google uses page load time in their ranking criteria.

When we think about website performance, often we talk about page load time. In WordPress, a common scenario when dealing with a load time issue is that it might be caused by a spike in the admin-ajax.php file. In this article, you’ll learn how to manage plugin conflicts caused by spikes in the admin-ajax.php file and reduce the request for callbacks to optimize your WordPress site’s load time.

What is the admin-ajax.php File in WordPress?

On 2013, WordPress version 3.6 was introduced along with Heartbeat API at its core. WordPress Heartbeat API is built as a communication protocol between the browser and the server. It uses admin-ajax.php to send a request to the server and trigger events (or callbacks) when receiving data. The main features of the Heartbeat API are:

  • Auto Saving

When you write a piece on WordPress, save it as a draft, and continue working on it, WordPress automatically saves any addition you make.

  • Post Locking and Login Notification

In a collaborative WordPress site, you’ll receive a pop-up whenever you try to write/edit a post that another user is currently working on. You’ll also get a popup notification when your session is expired, and a new login is needed to keep working on your post.

Problems That admin-ajax.php Can Cause

Overflowing the admin-ajax.php file can cause a page load time issue, which is a serious problem. The internet golden rule is that your site should fully load within 3 seconds or less. If it takes longer than that, chances are you give visitors a bad experience and drive them away.

Slow page speed can negatively affect your SEO ranking too. You should be aware that Google uses load speed as one of the indicators in their algorithm to rank sites. Besides, slow page speed means that the search engine can crawl fewer pages using their allocated crawl budget, and that will affect your pages indexation even further.

For some of us, the only time we’re dealing with this API is when we use speed test tools — such as GTmetrix, to figure out why admin-ajax.php is slowing down our websites.

Spikes in admin-ajax.php illustrated using GTmetrix

The causes for spikes can be from two different sources, either caused by third-party plugins or WordPress Heartbeat API request on the admin section. We’ll discuss it in more detail below.

How Plugins Can Overflow the admin-ajax.php File

Third-party plugins cause the most common problem when users see a spike on admin-ajax.php. If done correctly, AJAX is definitely a good thing, as developers usually use it to add functionality to their plugins. For example, developers can use AJAX requests and create a custom wp_query to display dynamic content on a cached page.

But sometimes when many plugins use these queries, they can cause an overflow. Thus it can create a spike and slow down the whole website. So, if you’re a developer, here’s a resource to properly implement AJAX in plugins.

As a website owner, you may need to diagnose the plugins first before disabling them. This is important to figure out if a particular plugin causes the load time issue.

Diagnosing Plugins

Conflicting plugins can cause a load time issue. The old school way is you can always disable all plugins to fix the problem, and re-enable them one by one using a process of elimination. But it’s definitely not a great solution.

We’ll use a more proper method to figure out the root cause of the problem with the following scenario.

Upon activating several plugins, you notice that your website needs a longer time to fully load. You then diagnose the site using GTmetrix. It’s a powerful free speed test tool that allows us to see the individual post response data.

Method A

Go to GTmetrix homepage, fill out your website URL, and click Analyze. It takes a while to analyze your site completely.

GTmetrix homepage

When finished, you’ll get a report of your website condition such as performance score and page details. Go to the Waterfall tab to inspect the website elements in more detail.

GTmetrix diagnose site using the waterfall tab

The Waterfall window will present all of your website’s elements. While the rest of the files look ok, you notice that POST admin-ajax.php takes a longer loading time.

GTmetrix details reported spikes in POST admin-ajax.php

Click on POST admin-ajax.php, and you’ll see four different tabs available: HeadersParametersPost, and Response. When diagnosing this kind of issue, the Post and Response tabs are the place you need to look at.

For this site, we see a clue in the Post tab as that request has something to do with the “count_hit” script.

POST admin-ajax.php details clicked on

That clue is leading us to suspect a certain post hit counter plugin that we’ve installed earlier. So, to prove that theory, we disable that plugin and run a second test with GTmetrix for our site.

Test speed result when the suspected plugin deactivated

It turns out our suspicion is correct. By disabling that plugin, we manage to reduce our page loads by 2 secs.

Method B

You can also use the Chrome developer console to find the suspected plugin.

Open your website. Right-click in the page -> Inspect. Alternatively, on the Chrome tab go to View -> Developer -> Developer Tools.

Click on Network tab and reload your website.

Chrome consol reports admin-ajax.php

In the filter box (right below the red dot) enter admin-ajax.php. You’ll see the culprit for the said issue. After that, you can disable the plugin and test if the problem still exists.

As a website owner, if you really need to use this plugin, make sure to use the most updated version. If you’ve done that and the problem persists, reach out the plugin developer while mentioning this case.

If the developer cannot resolve the issue yet, you can always replace it with a new one. The beauty of WordPress is there are many similar plugins to choose from. Just go to the WordPress plugins directory and select the most used and updated plugin that offers the same functionality.

Speeding Up the Backend of Your WordPress Site

Sometimes, WordPress Heartbeat API triggered in the backend of your site can also cause performance issue. As we noted earlier, this feature helps to autosave your work — to avoid losing projects when the unexpected happens, and to manage simultaneous writing/editing properly.

For example, the function will be triggered every time you write a post and keep the tab open. This can cause high CPU usage, as you see by the number of callbacks in the developer console below.

Admin-ajax.php triggered on backend

CPU use is an important issue for those who are using a shared hosting plan. Some hosting providers probably won’t tolerate a high CPU usage and it can eventually lead to suspensions, although that is not the case with Hostinger.

To resolve this issue, you can do two things, disable the heartbeat API or make the intervals between the checks longer. Since the first option is not practical, we’ll use the second one instead. To change the interval, you need a plugin called Heartbeat Control.

Go to your Dashboard -> Plugins -> Add New. Search the plugin by name, click install and activate it.

Upon activation, go to Settings -> Heartbeat Control Settings. Here, you can set different rules for different locations.

Heartbeat Control Settings

Since we want to minimize the callbacks frequency in the Post Editor, you can check that and set the number of requests higher than 15. In this case, we will set it to 200.

Once done, click Save Changes.

Conclusion

You’ve learned about the Heartbeat API and its byproduct, admin-ajax.php. You’ve also learned about the issues that arise when plugins overflow the function and cause slowdowns. You also know that the Heartbeat API itself can create a problem with your host should you don’t manage it properly.

Remember, to always check with GTmetrix when you feel a slowdown happen on your website. Go the waterfall tab, navigate to POST admin-ajax.php and see how everything is doing. Don’t just disable all plugins at once, as sometimes they might be not the culprit. But if they do, either replace them or limit the heartbeat API use.

Do you have similar experience dealing with admin-ajax.php? Drop a comment in the comment section below so the world can also learn from your story!

Updated on November 17, 2021

Was this article helpful?

Need Support?
Can't find the answer you're looking for? Don't worry we're here to help!
CONTACT SUPPORT