Categories: WordPress Plugins Reviews, Installation and TipsWordPress Tutorials, Tips and Guides
Reading Time: 5 minutes

In today’s cut-throat competition, a delay of even seconds in page load time can cost you a lot of potential customers. In many cases, users have little idea of the numbers of requests generated at the backend of the website in response to simple frontend actions.

Since WordPress is the most widely used CMS, there are tons of different themes and plugins that often cause issues that are difficult to troubleshoot. WordPress website users eventually audit their website speed performance and observe a common warning about admin-ajax.php server response time delay. For an optimized user experience, experts recommend that the websites should load within 3 seconds to grab visitors attention.

Whether or not you have expertise in SEO, you must take into account the server response time of WordPress website to improve the user experience.

While testing the speed of your WordPress using online speed testing tools, you might have observed that WordPress admin-ajax.php is responsible for the slow loading experience. In this article, I will talk about this file and how you can reduce server response time and the CPU usage by decreasing the number of requests generated by admin-ajax.php.

What is admin-ajax.php in WordPress?

Back in 2013, WordPress introduced WordPress Heartbeat API that provided several important functionalities such as the autosave feature, login-expiration and post lock warning while another user is writing or editing a WordPress post.

Two very prominent features of the Heartbeat API are:

1. Autosave

Whenever you save a draft of a post and continue working on it, WordPress automatically saves the additions to the post. There is a clear difference between the autosave and manually saving the draft. Check out the following screenshot that shows both types of saves:

2. Post Lock

Whenever you try to edit a post that another user is already working on, a pop-up warning about the situation will appear. There are three actions open to you.

The above-mentioned features are made possible because of the WordPress Heartbeat API that creates connections between the server and the browser for appropriate communication and responses.

WordPress Heartbeat API generates requests for communication with the server and triggers events on receiving data/response. This usually increases the load on the server and eventually slows down the WordPress Admin Dashboard.

A Live Example

I am logged into my WordPress dashboard and have started drafting a post. Next, I will leave the tab open for several minutes, and starts browsing in other tabs. The dashboard is still logged in, and you can see that admin-ajax is continuously sending requests.

According to the ticket mentioned above, admin-ajax.php in WordPress generates requests after every 15 seconds. The request can be any communication with the server.

Speed up WordPress Admin Dashboard

To speed up the WordPress backend, the best approach is to disable the Heartbeat API or at least set a longer time interval so that it does not hit the server after every few seconds.

Install Heartbeat Control Plugin

Login to your WordPress Admin Dashboard, navigate to Plugins >> Add New, search for Heartbeat Control, Install and Activate it.

Configure Heartbeat Control Plugin

Navigate to Settings >> Heartbeat Control Settings. There you will find three drop-down menus for configuring the plugin.

1. Allow Heartbeat:

You can select the areas where the Heartbeat API will work. There are three options to choose from:

  • WordPress Dashboard: This will enable the Heartbeat API for WordPress dashboard.
  • Frontend: This will enable API on the frontend.
  • Post Editor: Mark this checkbox, if you want to allow the Heartbeat API to be enabled on autosave and post lock features.

2. Disable Heartbeat:

Select this if you want WordPress Heartbeat API to disable on particular locations. Be careful while choosing the locations because other plugins might also be using the WordPress Heartbeat API. If you are the sole user of the WordPress backend, I would suggest disabling it everywhere and then check whether it breaks the website. However, if your site has more than one user who contributes regularly, I would propose that you allow the Heartbeat API only on the post edit pages.

3. Modify Heartbeat:

This drop-down allows you to set the time interval, ranging 0 – 300 seconds to execute admin-ajax requests. By setting it to 120 seconds, the request will be generated after every 120 seconds. That will drastically reduce the load on the server. Adjust it according to your needs.

Create Multiple Rules

You can create multiple rules based on your requirements. For example, you want WordPress Dashboard to trigger on 120 seconds but Post Editor to be triggered on 60 seconds. To do this, you need to create two rules. One for the WordPress Dashboard and other for Post Editor and set their frequency to 120 and 60 respectively.

Detect Plugins That Use the Heartbeat API

Now that you have set up everything, it is time to check which plugins are using the admin-ajax.php file and slowing down the website.

Go to GTmetrix, enter the URL of your site. It will take a few moments to analyze the site. Once done, navigate to Waterfall tab and you will see how much time a file is taking to connect and response. Scroll down a bit, and see if there is an entry for POST admin-ajax.php. If yes, expand it and navigate to the Post tab. From here, you can identify the culprit plugin. In my case, the plugin “desktop switch” is using the admin-ajax.php file and is continuously sending requests to the server. This is the time to make a decision, either replace it with another plugin or cross your fingers.

Final Words

Considering its feature set, the Heartbeat API is very useful on your WordPress website. However, if not used correctly, it can increase the load time of a WordPress backend and the front end by sending to and fro WordPress admin-ajax requests.

There are only two solutions for this issue. Either, disable the Heartbeat API/enable it in a few locations only, or upgrade to a hosting plan that could handle the load of the requests and also reduce server response time.

If you are using any caching plugin, such as W3TC, don’t forget to disable the object cache. This will also speed up the WordPress dashboard.

If you have any suggestion or query, feel free to post a comment below. I would follow it up ASAP!

Mustaasam Saleem :Mustaasam is the WordPress Community Manager at Cloudways - A Managed WordPress Hosting Platform, where he actively works and loves sharing his knowledge with the WordPress Community. When he is not working, you can find him playing squash with his friends, or defending in Football, and listening to music. You can email him at mustaasam.saleem@cloudways.com