Note: This option is available in the Pro version starting from v1.2.2.0.

By default, Asset CleanUp Pro is disabled whenever a REST API call is made. As there is no front-end to optimize in this situation (e.g. nothing to alter on the HTML source code), it’s better to avoid triggering the code from the plugin when it’s not necessary. This is also a safety measure in case the wrong rules are set in “Plugins Manager” — “IN FRONTEND VIEW (your visitors)” and the REST API calls are affected (e.g. not working anymore or having incomplete responses from the calls due to unloading rules that get triggered).

However, some experienced users have websites where lots of REST API calls are made and they are often slow. Some plugins use lots of useless database queries and have PHP code that is not well-optimized. This can slow down the REST API calls considerably and for someone who knows what he/she is doing, unloading plugins that aren’t needed from “Plugins Manager” could be a good idea.

The following constant needs to be added to wp-config.php (note that it should be added BEFORE the line where “wp-settings.php” is required):

define('WPACU_LOAD_ON_REST_CALLS', true);

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

The moment this constant is set to true, any unloading rules from “Plugins Manager” — “IN FRONTEND VIEW (your visitors)” will take effect if the URI matching is done, based on the RegEx rule. The following option needs to be used: “If request URI matches these RegEx(es):“. By default, the prefix for REST API calls is “wp-json“. If you want to stop a plugin loading on any REST API call, you can use the following RegEx: #/wp-json/# (see the print screen below).

If the REST API calls have been working fine before and suddenly they stopped working after you enabled this option (placing that code snippet in wp-config.php), it means some of the unload rules are interfering with the calls (e.g. some plugins are using the REST API to gather information) and it’s better to deactivate it (remove the snippet) or if you’re keen to still have the REST API calls load faster, then consult with a developer about it by checking the errors from the browser’s console.

Was this post helpful?