For website owners, optimising website performance is crucial. Poor performance can negatively impact visitor experience and even harm SEO rankings.
Page load time is often a key factor in website performance. In the case of WordPress, if you are experiencing slow page load times, it could be due to the admin-ajax.php file.
This article will teach you how to minimise plugin conflicts that can cause spikes in the admin-ajax.php file, as well as how to reduce the number of callbacks to optimise your WordPress site’s load time.
What is the admin-ajax.php File in WordPress?
WordPress version 3.6 was released in 2013, which included the Heartbeat API at its core. The WordPress Heartbeat API is designed as a communication protocol between the server and the browser. It utilises admin-ajax.php to send requests to the server and initiate events (or callbacks) when receiving data. The key features of the Heartbeat API include:
Autosave – Whenever you create a draft and continue working on it, WordPress automatically saves any changes you make.
Post Locking and Login Notification – In a collaborative WordPress website, you will receive a pop-up notification when attempting to write or edit a post that another user is currently working on. You will also receive a notification when your session has expired, and a new login is required to continue working on your post.
Issues Caused by admin-ajax.php
If the admin-ajax.php file overflows, it can lead to page load time problems, which is a serious issue. The golden rule of the internet is that your site should load fully in three seconds or less. If it takes longer than that, visitors are likely to have a negative experience and may leave your site.
Slow page speed can also have a negative impact on your SEO ranking. You should be aware that Google uses load speed as one of the indicators in their algorithm to rank sites. Additionally, slow page speed means that the search engine can crawl fewer pages using their allocated crawl budget, which can further affect your pages’ indexation.
How Plugins Can Cause the admin-ajax.php File to Overflow
The most common reason for an admin-ajax.php spike is third-party plugins. When used correctly, AJAX is a beneficial tool for developers to enhance their plugins’ functionality. For instance, developers can use AJAX requests to create a custom wp_query and display dynamic content on a cached page.
However, if multiple plugins use these queries, they can cause an overflow, resulting in a spike that slows down the entire website. If you are a developer, you can use the available resources to implement AJAX correctly in your plugins.
As a website owner, you may need to diagnose the plugins first before disabling them to identify the particular plugin that is causing the load time issue. This step is essential to determine the root cause of the problem.
Speeding Up the Backend of Your WordPress Site
The Heartbeat API triggered in the backend of your WordPress site can cause performance issues. As previously mentioned, this feature helps to autosave your work and manage simultaneous writing/editing. However, the function can be triggered each time you write a post and keep the tab open, resulting in high CPU usage.
High CPU usage is a critical issue, particularly for those who use shared hosting plans. Some hosting providers may not tolerate high CPU usage, which can lead to suspensions.
To resolve this issue, you can either disable the heartbeat API or increase the intervals between the checks. Since disabling the API is not a practical solution, we recommend increasing the intervals instead. The default interval for WordPress Heartbeat API calls is 15 seconds you could change this to 60 or 120. WP Rocket has a nice and easy plugin ‘Hearbeat Control‘ you can use to achieve this.