Table of Contents
Content Error or Suggest an Edit
The following article provides information on the WordPress admin-ajax.php function and a list of WordPress Plugins using admin-ajax.php in a manner that results in performance issues with your WordPress site.
AJAX allows websites to communicate with servers in the background without reloading the entire page. It enables the creation of dynamic and interactive web applications. WordPress leverages AJAX to enhance the user experience by providing features like live updates, form submissions without page reloads, and more.
When an AJAX request is made to admin-ajax.php, WordPress examines the request to determine the appropriate action to perform. The request includes parameters such as the action name and any additional data required to process the request.
WordPress provides various hooks and actions developers can use to extend its functionality. In the case of admin-ajax.php, these hooks allow developers to register their custom AJAX actions and associate them with specific functionalities.
Why does using admin-ajax.php cause performance issues? The following two articles go in-depth into why admin-ajax.php should be avoided completely when developing a plugin, especially for any front-end non-logged-in requests.
- WP REST API vs admin-ajax.php vs Must-Use Plugin: Handling AJAX Requests in WordPress – Delicious Brains
- Don’t Use Admin-Ajax – blog.julien-maury.dev
- 10up Engineering Best Practices
The following Github issue is the first step in solving the performance issues with admin-ajax.php
If you’re in a position where you’re seeing many admin-ajax.php requests in your access log and your WordPress site is slow or you want to know more about the requests. There is no native method in WordPress to investigate these requests, so I decided to make a mu-plugin that logs each request to a log file.
You simply drop the ajaxlog.php script into your wp-content/mu-plugins folder and then a log will be generated within the same folder.
It’s suggested to remove the ajaxlog.php file after you’ve gathered the data you require, and delete the log file from your server.
As mentioned in the GitHub issue, there was a gist that has now been forked and updated to work with WordPress 6.1 that is a drop-in replacement for admin-ajax.php
I haven’t tested this, so you must use this code carefully.
The long-term solution is most likely to build a user-ajax.php handler that is bare-bones and performant. The admin-ajax.php is still required for backend-related actions that require more code than a front-end request. This is just a suggestion. Hopefully, the WordPress performance team will figure out something.
- 03/10/2023 – Added WordPress Performance team Github Issue.
- 04-17-2023 – Added additional video and embedded Youtube videos.