Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
Minify's a great plugin, i might add. –  Kyle Yeo Nov 12 '12 at 2:01
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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