0

I'm currently playing around with AJAX forms, but I've noticed that admin-ajax.php is quite slow. If I simply return the word 'test', it takes around 1400ms.
I'm assuming it's because it's loading WordPress core which might slow it down a bit.

I've added the form handling as a plugin, hoping that might help speed things up over adding it to functions.php

/*
Plugin Name: Form test
*/
add_action( 'wp_ajax_form_test', 'form_test' );//logged in
add_action( 'wp_ajax_nopriv_form_test', 'form_test' );//not logged in

function form_test(){
   echo 'test';
   die();
}

Then I've gone to /wp-admin/admin-ajax.php?action=form_test

Is there anything I can do to speed this up a bit?

  • Have you benchmarked it? Also: Have you tried turning all plugins off and switched to a default theme? – kaiser Oct 21 '14 at 13:28
  • This is asked relatively often, please see Ajax takes 10x as long as it should/could for starters. – Rarst Oct 21 '14 at 13:40
  • Hi @kaiser I'm on a multisite setup (with domain mapping), so I created a new site with only the form test plugin activated. I'm getting 2250ms on this site. What do you use for benchmarking? – Chris Oct 21 '14 at 13:44
  • Interesting. I've disabled heartbeat on the original site and got the response to around 1s. Then I set up a new site with twenty-fourteen theme, no plugins and the custom ajax handler. The response comes in around 2.2s. I can't explain why this is taking longer than a fully loaded theme with plugins. So I'll probably stick with admin-ajax.php. – Chris Oct 21 '14 at 14:10
  • After further testing with some JSON remote data and a HTML form, admin-ajax.php comes in around 4s and the custom ajax method around 3s. So it seems there is a benefit there. – Chris Oct 21 '14 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.