The WordPress Heartbeat API is a common point of discussion when it comes to speeding up a WordPress site. While it facilitates a number of key WordPress features, it can lead to significant CPU usage if left unchecked.
In this guide, we’ll take a look at what WordPress Heartbeat is, what it does, and how you can easily control its functionality to optimize your site’s performance.
The WordPress Heartbeat API is a system that allows WordPress to send data between the server and the browser in real time. This rapid two-way communication enables features like auto-saving, revision tracking, session management, and post locking (when one user tries to edit a post that another user is currently editing).
It’s called “Heartbeat” because it simulates a pulse, with data being exchanged every 15-60 seconds.
The Heartbeat API is also available to developers, who can use it to add similar functionality to themes and plugins.
If you’re interested in the technical details, WordPress.org explains:
When the page loads, the client-side heartbeat code sets up an interval (called the “tick”) to run every 15-60 seconds. When it runs, heartbeat gathers data to send via a jQuery event, then sends this to the server and waits for a response. On the server, an admin-ajax handler takes the passed data, prepares a response, filters the response, then returns the data in JSON format. The client receives this data and fires a final jQuery event to indicate the data has been received.
In simple terms, this means the browser and the server remain in contact for the duration of a user’s session, exchanging information at regular intervals.
Let’s take a look at what the WordPress Heartbeat API actually does, and what sort of functionality it brings to the table.
One of the most valuable benefits of the Heartbeat API is the ability to automatically save drafts and revisions while you’re working—without ever having to click the “Save Draft” button.
The last thing you want is to lose your hard work because you accidentally closed your browser or clicked a link to another page. In earlier versions of WordPress, this was such a common occurrence that many people were hesitant to compose content in the WordPress editor, instead opting to write in a separate application and copy the finished product into WordPress later.
Thankfully, the Heartbeat API prevents that sort of disaster by regularly sending the latest version of your post from your browser to the server.
Another potentially disastrous scenario is when two users try to edit the same post simultaneously. There’s no way that ends well—someone’s work is bound to get lost.
However, the Heartbeat API checks in regularly to let WordPress know that a user is currently editing a post. When someone else attempts to edit that same post, they’ll be met with this warning:
This is an important safeguard made possible by Heartbeat.
Developers can use the Heartbeat API to make use of the “pulse” in their own themes and plugins.
One such example would be real-time notifications, delivered without requiring the user to reload the page. There are also plugins that enable the comment section to update in real time.
These are just a couple of examples. There are countless other use cases for real-time client-server communication.
As we’ve seen, the Heartbeat API can be incredibly useful for adding real-time functionality to WordPress. However, these features come at a cost.
At every “pulse” of the WordPress Heartbeat, a POST
request is sent to /wp-admin/admin-ajax.php
.
This happens every 15 seconds on post edit pages, and every 60 seconds on the main WordPress dashboard.
Yes, these requests are sent every 15-60 seconds—even if you just log into WordPress and leave your browser open.
As you can imagine, this behavior can have a notable impact on your site’s performance, especially if you have multiple users.
If your web host is showing high CPU usage attributed to /wp-admin/admin-ajax.php
, the Heartbeat API is likely to blame.
If you find that the Heartbeat API is using excessive resources, you can speed up your website by either disabling it or managing the frequency of the pulse.
In most cases, it’s safe to disable Heartbeat if you’re the only person working on your site and you know you don’t have any important plugins or functionality that rely on it. With that said, it’s still a good idea to test this on a staging site first, if you can.
Keep in mind that if you completely disable Heartbeat, you will lose features like auto-saving, post locking, and any real-time functionality added by your plugins or theme. If you need these things, I recommend modifying the pulse frequency instead (see below).
Disabling the Heartbeat API can be achieved in two main ways:
To disable the Heartbeat API, simply add the following code to your theme’s functions.php
file:
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}
This will completely disable the Heartbeat API on your website. If you want to reenable it later, simply remove that code from your theme.
To effectively disable the Heartbeat API in WordPress, you can use the following code snippet:
This code snippet should be added to your theme’s functions.php file or a site-specific plugin. It works by deregistering the ‘heartbeat’ script, effectively stopping the Heartbeat API from running.
If you don’t want to disable Heartbeat completely, you can limit the pulse frequency by installing the Heartbeat Control plugin.
Heartbeat Control is a highly rated free plugin from the developers of WP Rocket, which we found to be the best WordPress caching plugin.
Once you’ve installed Heartbeat Control, log into WordPress and go to Settings > Heartbeat Control Settings
.
On this page, you can add various rules that dictate how the WordPress Heartbeat is allowed to behave on your website.
For each rule, you can choose to Allow Heartbeat, Disable Heartbeat, or Modify Heartbeat. The rule will apply only to the locations you select—e.g. the WordPress Dashboard, Frontend, or Post Editor.
If you choose to modify Heartbeat, a slider will appear where you can specify your desired pulse frequency in seconds. You can set it to anything from 15 to 300.
If you want to set different limits for different parts of your site, you can simply create multiple rules.
To configure the Heartbeat Control plugin, go to your WordPress dashboard. Navigate to the ‘Settings’ menu and select ‘Heartbeat Control’. Here, you can access and adjust the plugin’s settings according to your preferences.
Heartbeat Control plugin, start by installing it from the WordPress plugin repository. After installation, activate the plugin via your WordPress dashboard. Once activated, you can immediately begin managing and controlling the Heartbeat API’s behavior on your site.
According to a user’s firsthand experience shared in the passage, disabling the Heartbeat API resulted in noticeable improvements in their website’s performance. Specifically, they observed a substantial reduction in their homepage’s loading time, which decreased from four seconds to just 1.9 seconds. Additionally, there was a significant decrease in the total page size by approximately 200kb. These optimizations contributed to an improved Google PageSpeed score by two points, indicating enhanced overall website efficiency and speed.
When evaluating changes to critical WordPress components like the Heartbeat API, it’s crucial to understand how they can affect SEO. Disabling the Heartbeat API can indeed influence SEO outcomes, with predominantly positive effects.
Key Benefits Explored:
Disabling the Heartbeat API can bring substantial enhancements to website performance metrics directly linked to SEO effectiveness. By boosting page speed, reducing page size, and elevating PageSpeed scores, your site becomes more competitive in search engine results. This improvement can translate into increased visibility, higher traffic volumes, and potentially greater conversion rates. It’s important to carefully weigh these benefits against any potential drawbacks and to monitor your site’s functionality closely after implementing such changes.
Common Questions and Comments About the Heartbeat API in WordPress
The WordPress Heartbeat API enables a lot of great features by providing real-time communication between the browser and the server. Auto-saving and post locking, for example, solve some of the most frustrating problems from earlier versions of WordPress.
These features do come at a cost, though. The more time you spend in your WordPress dashboard, the more CPU requests will pile up, leading to higher resource usage, slower performance, and in more serious cases, hosting account suspensions.
Luckily, it’s quite simple to mitigate those issues by managing the behavior of the WordPress Heartbeat API.
If you have any questions about WordPress Heartbeat, please feel free to leave them in the comments below!
If you’re looking for fast wordpress hosting as well as done-for-you updates such as optimizing and managing your WordPress Heartbeat API effectively , check out our hosting packages by clicking the button below:
Are you looking to reset a WordPress site and start fresh? Reset a WordPress Site…
Ready to build your online presence? Choosing the right platform between Wix vs. WordPress is a crucial first…
Changing your favicon in WordPress is a small yet powerful way to improve your website’s…
Have you been searching for the easiest way to share PDF files directly on your…
Ever notice how professional websites seamlessly display social media icons in their headers? Adding social…
WordPress caching is an incredible tool for boosting your website’s performance. It helps deliver faster…