WordPress.org

Ready to get started?Download WordPress

Forums

Optimizing WP, combining plugin javascripts and css? (3 posts)

  1. tta
    Member
    Posted 3 years ago #

    Hello,

    Recently launched a site on a dedicated server, unfortunately I've got a big bunch of http requests that slows the site down as soon as there's traffic. I've got a grade D on Yslow.
    I know of minifying css and javascript, and also of combining in order to get less http requests.

    Problem is, most of them are from various plugins used on the site. Slideshow gallery, events-calendar, wp e-commerce, mtouch-quiz, contactform etc etc etc... and many of them are located in the head of the document, and will break plugins used on the site if moved around.

    Is it somehow possible to combine plugin javascripts? Will I have to manually edit the plugins and point them to a manually combined javascript every time they call on some JS? Same goes for all the css files the plugins are requesting.
    Anyone had a similar problem and found a solution?

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    you can remove css and properly registered javascript from your header this way. Put this in your theme's functions.php.

    add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
    function my_deregister_styles() {
    	wp_deregister_style( 'wp-pagenavi' );
           // deregister as many stylesheets as you need...
    }
    
    add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
    function my_deregister_javascript() {
           wp_deregister_script( 'contact-form-7' );
           // deregister as many javascript files as you need...
    }
  3. CockpitSeeker
    Member
    Posted 2 years ago #

    @tykho:
    you can try combining files for your issue.
    W3-total-cache allows you to do it for both CSS and JS, which even gives you the option to modify the files order for the output combined file and the ability to exclude some files if you still have dependency issues.

    I do see a problem though.
    With my particular setup, this combining plugin breaks and I figured I would manually combine, with the combine.php script of Rakaz.

    Following the instructions, when setting up the script, I see 1 problem:

    • wordpress structure does not have only 1 folder for CSS
    • same for JS

    given that every theme and plugin has its own set of files, within their own path.

    Thus when looking at:
    $cssdir = dirname(__FILE__) . '/css';
    to specify a CSS folder, I wonder if it would be syntaxly correct to change it to, for instance:
    $cssdir = dirname(__FILE__) . '/wp-content/themes/theme1/css,/wp-content/plugins/plugin1/css,wp-content/plugins/plugin2/css'; (to specify various folders)

    Same would go with the JS folder structure.

    Is such a syntax valid in php?

Topic Closed

This topic has been closed to new replies.

About this Topic