Faster Ajax Calls In WordPress By Using The AjaxFlow Plugin

Is it possible to achieve faster Ajax Calls in WordPress? You bet it is possible and you can start doing it right now with very little edits to the code you already have in place. We are going to be using a little plugin called AjaxFlow to speed it up, but first let’s go over the regular, slow way of doing Ajax Calls in WordPress.

Meet Ajaxflow

By installing this plugin in your Website, your Ajax calls will be so fast you’ll think it’s sorcery, but it is not, I think it’s not. All kidding aside, the plugin basically tells WordPress to load the bare minimum instead of loading the whole WordPress environment, thus speeding everything up and resulting in much faster Ajax calls. I’m talking calls that would normally would take 3-5 seconds on a good server down to 100-300 milliseconds.

How To Use Use AjaxFlow

Using AjaxFlow is super easy, and if you are already using regular Ajax calls within WordPress using wp_ajax_nopriv_$action and wp_ajax_$action, converting to AjaxFlow can be done in minutes.

What Are The Differences?

  • Ajax calls need to be made to /ajaxflow/$action, meaning that /wp-admin/admin-ajax.php is no longer used.
  • Passing the action parameter in your Ajax request is no longer necessary since we include the action in the call endpoint as explained above
  • ajaxflow_nopriv_$action and ajaxflow_$action must be used in your PHP code instead of using wp_ajax_nopriv_$action and wp_ajax_$action

AjaxFlow Example

    type: 'POST',
    url: '/ajaxflow/get_subcategories',
    data: { parent_id: top_category },
    success: function( data, textStatus, jqXHR  ) {
        // Do Some stuff with data
    error: function( jqXHR, textStatus, errorThrown ) {
// Add actions in your class constructor
add_action( 'ajaxflow_get_subcategories',               array( $this, 'get_subcategories' ) );
add_action( 'ajaxflow_nopriv_get_subcategories',        array( $this, 'get_subcategories' ) );

// Function to handle the Ajax call
public function get_subcategories() {

If for some reason you get an error message other than zero saying your call $action doesn’t exists, then it means you have forgotten to add the Ajax handler in the back-end or you didn’t add it properly since it can’t find it.

That’s it, give it a try and watch your Ajax calls fly.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s