Everyone who reads my blog knows I have OCD when it comes to optimizing and improving the speed of WordPress sites. If you’ve stumbled upon this article, chances are you’re trying to figure out why your WordPress site is slow.
After implementing various speed optimization tips, you may have concluded that the culprit is the file admin-ajax.php
.
But why is this file causing performance issues? In this article, I’ll explain the root cause of the problem and show you how to control it effectively using WP Rocket.
There are two main issues with admin-ajax.php:
- WordPress Core: Excessive, and often unnecessary, use of the server’s CPU caused by core functionality.
- Third-Party Plugins: Plugins that trigger excessive AJAX calls through
admin-ajax.php
, often leading to degraded frontend performance.
Understanding admin-ajax.php and the Heartbeat API
In WordPress version 3.6, the WordPress Heartbeat API was introduced to enable communication between the browser and the server. This API facilitates session management, post revision tracking, and automatic draft saving in WordPress.
The Heartbeat API uses the /wp-admin/admin-ajax.php
file to send AJAX calls from the browser. While this is useful for real-time updates in the admin dashboard, it can result in excessive POST requests that overburden your server’s CPU and generate unnecessary PHP calls.
Example: Imagine having multiple tabs open in your browser, all using the Heartbeat API. Each tab sends requests to
admin-ajax.php
at regular intervals, potentially overloading your server.
Optimizing Heartbeat API Settings with WP Rocket
WP Rocket provides built-in settings to manage and optimize the Heartbeat API, allowing you to control its behavior without writing custom code. Here’s how you can use WP Rocket to manage the Heartbeat API:
Step 1: Navigate to Heartbeat Settings
In your WordPress dashboard, go to Settings > WP Rocket > Heartbeat. Here, you’ll find options to control the Heartbeat API for different areas of your site.
Step 2: Adjust Heartbeat Behavior
WP Rocket offers three main options to manage the Heartbeat API:
- Reduce Activity: Decreases the frequency of requests sent to
admin-ajax.php
. This is the recommended option for balancing performance and functionality. - Disable Everywhere: Completely disables the Heartbeat API across your site. Use this only if you’re confident it won’t disrupt essential functionality, such as autosave.
- Disable by Location: Targets specific areas, such as:
- Dashboard: Disables Heartbeat API in the WordPress admin dashboard.
- Post Edit: Limits Heartbeat API activity to post-edit screens.
- Frontend: Disables Heartbeat API for any frontend AJAX calls.
Step 3: Choose the Best Settings
For most WordPress sites, I recommend reducing the activity rather than disabling the Heartbeat API entirely. Here’s an example configuration:
- Dashboard: Disable or reduce activity, as this area doesn’t often require frequent updates.
- Post Edit: Set to reduced activity to retain autosave and collaboration features.
- Frontend: Disable entirely unless specific plugins rely on frontend AJAX calls via Heartbeat.
This configuration strikes a balance between improving performance and maintaining essential features like autosave or plugin functionality.
How WP Rocket Improves Performance
By reducing the frequency or disabling the Heartbeat API in unused areas, WP Rocket significantly minimizes the number of requests sent to admin-ajax.php
. This reduction directly decreases server load, enhances CPU efficiency, and improves page load times.
For instance, setting the Heartbeat interval to 60 seconds instead of the default 15 seconds can drastically cut down on unnecessary requests, especially on sites with multiple editors or heavy admin usage.
Analyzing Plugins Using admin-ajax.php
In addition to optimizing the Heartbeat API, it’s important to identify plugins that overuse admin-ajax.php
.
Use Chrome Developer Tools to inspect AJAX requests and pinpoint the plugins responsible for excessive server calls. This will help you decide whether to configure, replace, or disable those plugins.
Conclusion
Managing the WordPress Heartbeat API is essential for maintaining optimal performance, particularly on busy sites. WP Rocket provides an intuitive way to control the Heartbeat API, offering flexible options to reduce server load while preserving necessary functionality.
Related Articles on WordPress Speed Optimization: