Here http://drupal.org/project/conditional_styles is written:

For example, if you are re-generating the $styles variable in your theme's preprocess_page function by calling $vars['styles'] = drupal_get_css() (old versions of the Zen theme did that), you will either need to stop doing that (adding stylesheets with drupal_add_css in your template.php is bad for performance anyway) or, after you are done screwing with $var['styles'], you can $var['styles'] .= $var['conditional_styles']; to add them back in.

What is right way to add own (color) CSS to some custom pages?
Otherwise then edit template.php and add CSS via drupal_add_css / drupal_get_css?

Comments

JohnAlbin’s picture

Title: What is right way to add own (color) CSS to some pages? » What is right way to add CSS to some pages?
Status: Active » Fixed

When you have CSS aggregation turned on (and you should), Drupal has to combine all the stylesheets together and save it in a new file.

But when you conditionally include an additional stylesheet via drupal_add_css(), you force Drupal to rebuild the aggregated stylesheet for that page. Which is 1.) a significant performance hit for Drupal and, worse, 2.) a big performance hit for your website’s users because they have to download a new really large aggregated stylesheet. :-p

So, the way to avoid that is to:

  1. non-conditionally include your stylesheets by adding them to your theme’s .info file,
  2. add some conditional code to your theme’s mysubtheme_preprocess_page function (in template.php) that adds a new class to the $body_classes variable:
    function MYTHEMENAME_preprocess_page(&$vars, $hook) {
      if ($condition) {
         $vars['body_classes'] .= ' conditional-class-1';
      }
    }
    
  3. prefix all the rules in your "conditional" stylesheet with the class that you conditionally added in step 2.

So now the aggregated stylesheet remains the same on each page request, but the styles that get applied depend on the body classes.

mattez’s picture

JohnAlbin THANX A LOT!
That's what I call right USEFUL clever answer post!
great :)

(more stuff like this here :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.