How To Disable Or Limit Heartbeat API
In other words, this API allows you to achieve real-time frontend updates. For example, showing other authors that certain post is currently being edited by another user. This is very useful for a blog with many authors. Still, many great features come at a great cost. Please read further below. This article is part of best useful tips for your WordPress.
What Is Heartbeat API
Basically, Heartbeat API is a round timer that will run continuously on your website. When your page is load, Heartbeat will create an interval that runs every 15 - 60 seconds. Each time upon completion, Heartbeat gathers data and send it to the server via a jQuery event and wait for a response.
Although this is a dream come true for developers which can lead to more possibilities, yet it has a drawback. In many cases, it will increase your CPU usage, PHP execution and inevitably slow down your website. This is inefficient and wasting especially for any bloggers on the shared hosting plan with the limited resource.
How To Disable Heartbeat API
I would highly recommend you to completely disable Heartbeat API if you meet two or more of the following conditions:
- You are the only user of your website which means there are no other authors, editors, etc.
- There is no need for you to use any features made possible by this API.
- You are always on the verge of reaching the limit of CPU usage or PHP execution set by your hosting provider.
To disable Heartbeat completely, all you need to do is copy and paste the following snippet into your functions.php or site-custom plugin. You might want to read how to create site-custom plugin or advantages of saving scripts in the site-custom plugin compared to functions.php.
By applying the above snippet, you will stop Heartbeat during WordPress initial phase. And essentially prevent any additional CPU usage or PHP execution that may be generated by Heartbeat.
Disable Or Limit Heartbeat API With A Plugin
Besides above approach, you can also disable or limit Heartbeat API with a plugin. There's a WordPress plugin called Heartbeat Control which allows you to disable or limit Heartbeat API with ease. It comes with the minimal setting but allows you to set any rules.
For example, you can choose which location you would like to apply those rules. You can choose to allow, modify or disable Heartbeat completely at the dashboard, frontend or post editor. On top of that, you can also set a frequency to any rules you create. Please take a look at the image below.
WordPress Heartbeat is indeed a great feature. Yet depending on circumstances, it may not suit for everyone. In any event, between two of approaches above, which is your preferred method to disable or limit Heartbeat API?
He is a web developer, a programmer, and a computer technician. He obsessed with coding and enjoy learning new things. In his spare time, he likes to play online games, musical instruments or watching anime and movies.