WordPress.org

Ideas

Better AJAX Endpoint for Plugins

  1. ibes
    Member

    12345

    If plugins want to use AJAX they typically use the admin-ajax.php

    There should be a better way to do this.

    Plugins who act in the frontend shouldn't call a function that is (for good reasons, I guess) located in /admin/

    Also the script loads a lot of WP internals and a lot of plugin code.

    So every time a slim plugin does a AJAX call and heavy plugins like woocommerce are activated, the answer will be slow.

    There are already some suggestions who to speed up AJAX responses like: https://coderwall.com/p/of7y2q/faster-ajax-for-wordpress

    But all the plugins I see use admin-ajax.php and they all put it in there custom wp_localize_script.
    So I guess it can be seen as best practice.

    Would be great to have a standard way to make AJAX calls that are slimer and faster.
    For example only load some of the most important WP internal scripts and only load this specific plugin.

    I am working on a little MU-Plugin that will help with specifying with plugins should be loaded for specific AJAX calls.
    That way I can reach enormous speed increases for things like simple read/write operations.

    I can't point out a perfect solution right now, but AJAX is not properly solved right now.

    Posted: 2 years ago #
  2. maybe try heartbeat control plugin

    Posted: 2 years ago #
  3. Drew Jaynes
    Inactive

    For what it's worth, The REST API largely serves to provide a better interface for plugins and themes doing all sorts of interactions, especially AJAX.

    Posted: 2 years ago #
  4. ibes
    Member

    12345

    Oh yes - the REST API will be a good replacement to to things via admin-ajax.php
    But at the moment it is the standard.

    I wrote a little boilerplate for an mu-plugin to speed up AJAX calls:
    https://github.com/ibes/shy-ajax-handler

    Posted: 2 years ago #
  5. robcruiz
    Member

    You are absolutely right. AJAX is clunky in WP. I hate it. I write tons of plugins that utilize the ajax api, but once you get so many in there, it all get so slow! Feels too heavy. Besides your plugin, are there any other options you have come across. I tried following that link that you put in there for the custom fake ajax.php file. I haven't had any luck with it, not sure what I'm doing wrong, I just can't seem to get a response. I'm hoping WP changes all that here soon. However, I am doubtful as there are so many plugins utilizing the existing API.

    Posted: 1 year ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    7 Votes
  • Status

    This idea is under consideration