Skip to:
Content
Pages
Categories
Search
Top
Bottom

Performance of css Stylesheets


  • mcpeanut
    Participant

    @mcpeanut

    Ok i have been tweaking my js scripts via combining them and serving them as 2-3 cached files for performance instead of having them all load separate scripts via a few plugins.

    QUESTIONs: I know i can do the same with the css but im wandering if there would be any benefit doing it this way or actually combining the css manually into 1 large css file using my style.css where all my custom css is also located by using wp_deregister_style to stop the original stylesheets from loading? Would this be beneficial rather than using a plugin to minify and combine them? Is 1 big minified cached version loading on every page better than loading independent stylesheets as an when needed? what are your takes on this before i start to manually do this?

Viewing 7 replies - 1 through 7 (of 7 total)

  • rosyteddy
    Participant

    @rosyteddy

    Isn’t one always better?

    No. If you are thinking of creating a page-specific CSS file and somehow concatenating the parts it needs into that single file, don’t. It seems like, hey, one request is better than three! But then you aren’t leveraging the browser cache at all.

    http://www.hanselman.com/blog/TheImportanceAndEaseOfMinifyingYourCSSAndJavaScriptAndOptimizingPNGsForYourBlogOrWebsite.aspx

    One, Two, or Three

    But I will like to know your own practical experiences. Thanks.


    mcpeanut
    Participant

    @mcpeanut

    @rosyteddy a couple of good reads there man, i like to read through the comment sections on articles like the ones above because there is some good points raised, there are alot of varied opinions as how to effectively pull this off dependent on the complexity of your site, which i would consider mine as quite complex, the reason for the questions and advice is because of how complex i consider the website to be, i have alot of stylesheets for various different things here there and everywhere loading when not needed etc, in the past i have used plugins to successfully combine and serve them as one cached minified version etc.. but i was just wanting to go more in depth with it and configure it all myself to run at an optimum level.

    I am going to be messing around with this over the next few days and will get back to you on what i feel was the best way to do it, any more advice off anyone else who has tackled doing this manually for wordpress/buddypress give us a shout.


    Henry Wright
    Moderator

    @henrywright

    Hey @mcpeanut,

    There’s no right and wrong way but this is what I do:

    Put all of your global CSS properties into style.css. for example, styles that related to your header, footer and main templates and then conditionally enqueue stylesheets that are used less regularly so that they’re only loaded when absolutely necessary.


    mcpeanut
    Participant

    @mcpeanut

    @henrywright cheers henry any little info and suggestions how others do it always helps, i know that it mainly boils down to each specific website how this is done in the best possible way, and alot of it can depend on how many stylesheets various plugins load, i wish more developers would give you an option in the backend to use your own stylesheets as standard and let you just turn them off from loading, i know more and more plugins are giving you this option but there are alot that still don’t, i like to customize everything myself and would rather not have to dequeue these stylesheets manually. its quite annoying.


    Henry Wright
    Moderator

    @henrywright

    You can dequeue style sheets with wp_dequeue_style(). You just need to find the handle used when the style sheet you want to remove is enqueued. Something like this:

    $handle = 'something-here';
    wp_dequeue_style( $handle );

    You probably know that though but I thought I’d post in case anyone else might be wondering how it’s done.


    mcpeanut
    Participant

    @mcpeanut

    yes that’s how ive been doing it henry, but cheers its a good idea like you said to post the code so others know what we are talking about lol


    mcpeanut
    Participant

    @mcpeanut

    you can also use something like this

    add_action( 'wp_enqueue_scripts', 'remove_default_stylesheet', 20 );
    
    function remove_default_stylesheet() {
        
        wp_dequeue_style( 'original-enqueue-stylesheet-handle' );
        wp_deregister_style( 'original-register-stylesheet-handle' );
    
        wp_register_style( 'new-style', get_stylesheet_directory_uri() . '/new.css', false,'1.0.0' ); 
        wp_enqueue_style( 'new-style' );
    
    }

    This way you can first dequeue/deregister styles you dont want and then register/enqueue the new stylesheets

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Performance of css Stylesheets’ is closed to new replies.
Skip to toolbar