Heavy use of admin-ajax.php
- JavaScript
Problem Summary
admin-ajax.php is WordPress’s legacy AJAX handler. It’s slow because it loads the full WordPress admin, processes nonces, and executes unnecessary hooks. Heavy use creates significant server overhead.
Performance Impact
- Full WP load: Every AJAX request loads entire WordPress
- Server CPU spike: Heavy processing per request
- Increased TTFB: Each admin-ajax.php call is slow
- Blocking resources: Often blocks critical rendering
How to Detect
- Server access logs: High volume of admin-ajax.php requests
- Query Monitor: Shows admin-ajax.php queries
- Chrome DevTools Network: Many admin-ajax.php calls
- GTmetrix: Flags admin-ajax.php usage
Solutions
1. Use REST API Endpoints
<?php
add_action('rest_api_init', function() { register_rest_route('custom/v1', '/action', [ 'methods' => 'POST', 'callback' => 'my_callback', ]);});2. Add Non-AJAX Fallbacks
Use regular form submissions when JavaScript isn’t available.
3. Cache admin-ajax.php Responses
<?php
add_action('admin_init', function() { header('Cache-Control: public, max-age=300');});4. Use wp-ajax.php Only When Needed
Check if you actually need WordPress loaded.
5. Frontend-Only AJAX
Create lightweight AJAX handlers that don’t load admin:
<?php
add_action('wp_ajax_nopriv_my_action', 'my_lightweight_callback');add_action('wp_ajax_my_action', 'my_lightweight_callback');