How can I reduce the amount of files loaded/included per plugin?

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.

Read More

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?

Related posts

Leave a Reply

3 comments

  1. 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.