Solution:2
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.
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.
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.
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.
Click on POST admin-ajax.php, and you’ll see four different tabs available: Headers, Parameters, Post, 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.
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.
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.
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.