4

I have a Wordpress site that uses several plugins, namely 8. Most of these plugins include a lot of their own JS and CSS files, some even include so much as 3 separate CSS files. One can imagine that this does a number on the amount of HTTP requests and thus the load time.

Many of these plugins also only get used on certain pages, yet the JS or CSS is still loaded on pages where they are not used.

All of theses files are included automatically in the through WP_head();. Is there a way I can manually include these files and then load them conditionally? Preferably without having to adjust the plugin code itself?

Are there other common practices regarding the many files included by a bigger number of plugins?

3 Answers 3

3

Previous versions of WordPress didn't really provide a good means to conditionally enqueue stylesheets and JavaScript within a plugin (i.e. only when needed). So most plugin authors enqueued both on every WordPress init/load, even if the plugin wasn't being used on a given page.

Current versions of WordPress allow for enqueuing later in the flow so you you can, for example, enqueue on your shortcode init/parse.

So you really have only a few options here:

  • Use Minify to reduce the file size and in some cases combine files to reduce the number of requests, file I/O, and bandwidth. (Already suggested by @m4t1t0)
  • Directly modify the plugins to prevent the enqueue if the plugin is not actually used on a given page.
  • Open a support ticket for the appropriate plugin and request the author to update the plugin.

Hopefully other users here might have some suggestions for you.

2
  • Minify's a great plugin, i might add.
    – Kyle Yeo
    Nov 12, 2012 at 2:01
  • "Directly modify the plugins to prevent the enqueue if the plugin is not actually used on a given page." I don't think that this is a good practice. The problem with directly modifying plugins is that you will have to make your edits on each update. Also, the more modifications you do for a plugin the more the chances of an update breaking your code.
    – Mugen
    Feb 18, 2020 at 4:27
2

You can try this plugin: http://wordpress.org/extend/plugins/wp-minify/ it allows you to consolidate and minify your JS and CSS

1

Besides WP Minify, I would recommend you to use the Selective Loading Plugin.
It'll help you load only the plugins you want to load based on pages/posts and categories and it will improve your WP's loading time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.