How to prevent loading of all plugin’s resources?

WordPress is loading all client resources of all plugins, not just the plugin of interest. It may make sense to load jqery globally but it makes no sense to load all other plugin’s Javascript in a back-end plugin.

Now, how can I prevent that WordPress is loading other plugin’s resources?

There’s wp_dequeue but I am not sure there is another callback at the end of loading all plugins, so I can clean it up alltogether myself. I am currently interested in filtering back-end plugin resources only.

ps: i am really stuck at this and I am actually very surprised that it seems to be designed like this, I mean, wp_enque is fine but WP doesn’t care for what it is ,so you need to do all the leg-work yourself. Simply imagine 2+ different Dojo/CommonJS/Require-JS based applications with their own configs and versions being loaded : trouble non stop, that’s what I am facing now.

thank you, any idea is welcome.

3 Answers
3

You could try echoing wp_head and wp_footer to see what they contain but unfortunately that’ll miss stuff some of the authors hardcode. Basically what I do is wp_dequeue/wp_deregister based on what I see being loaded in either the source, error-logs or even just looking within each of the installed plugins to see whats being called. I find it easier to download production sites to my local dev environment. Using Notepad++ I then click Search -> Find in all files -> Specify the plugins dir (or themes) on my local development environment and search for patterns like wp_enqueue even *.js and so on since I get a better picture and what can be loaded. I then make the needed changes on the live environment.

If you identify scripts you do not want, Pop them into a function that looks something like this inside your themes function.php file:

function wp_getridofscript() {
   wp_dequeue_script( 'jquery-ui-core' );
   wp_deregister_script( 'jquery-ui-core' );
}
add_action( 'wp_print_scripts', 'wp_getridofscript', 100 );

You can have as many as you want and don’t need to bother writing a separate function for each. IE:

function wp_getridofscript() {
   wp_dequeue_script( 'jquery' );
   wp_deregister_script( 'jquery' );
   wp_dequeue_script( 'jquery-ui-core' );
   wp_deregister_script( 'jquery-ui-core' );
}
add_action( 'wp_print_scripts', 'wp_getridofscript', 100 );

Leave a Comment