0

Here is my problem. Using Sass (from Zen theme) and on top of that Brunch, our compressed css file has over 4095 Selectors and is then compressed by Drupal (and still has over 4095 selectors in one files).

Do you know if there is a way to tell Drupal to compress files in smaller files in order to avoid the 4095 selector limit per files ?

  • 1
    I don't know about Zen, but with sass in you include the _*.scss files in your main style.scss. Why you don't try to separate some logic on different files? – tvl Oct 30 '14 at 9:59
  • Actually we have a lot of different .scss files but we also have Brunch that aggregate all the generated css files in one. – pbonnefoi Oct 30 '14 at 10:02
  • 2
    Sorry I didn't get it. In your sass file collection you have more than IE limit 4095. Then you compile it to css and merge them & minify them with Brunch. But you don't want to exceed the 4095 per stylesheet? So you want Drupal to break the css for you, after you combine them with Brunch? Or you have 3-4 files that Drupal aggregates them and then you have a single file with many selectors? – tvl Oct 30 '14 at 10:10
  • We have 4 files compressed generated by Drupal. If we could have something like 8 files instead, it might work. We are also looking into brunch configuration and that might not be related to Drupal. – pbonnefoi Oct 30 '14 at 11:23
1

Lets say your my_theme.info have

stylesheets[all][] = css/my_theme_1.css
stylesheets[all][] = css/my_theme_2.css
stylesheets[all][] = css/my_theme_3.css
stylesheets[all][] = css/my_theme_4.css

And you don't want to aggregate these files in a single one (exceed IE limit 4095 selectors)(also I assume that is already minified by Brunch)

Remove the above lines from your .info or comment out.

Then add an html preprocess function (on the main template.php or if you have an html.preprocess.inc file)

function my_theme_preprocess_html(&$variables) {
  drupal_add_css(drupal_get_path('theme', 'my_theme') . '/css/my_theme_1.css', array('preprocess' => FALSE));
}

The drupal_add_css will add the css but 'preprocess' => FALSE will prevent Drupal to aggregate them.

(It's a bit hacky but it works)

  • Thanks, your solution is good. We modified Brunch to generate 3 files instead of 1 and added the files directly in the template (without going through .info) I also had an other problem on top of that because we were using the CDN module (so I had to have the proper url if CDN was activated) :-D But now everything works on IE. – pbonnefoi Oct 30 '14 at 17:27
1

I found a very interesting module that can handle the 4095 limit for drupal compressed files and many other css and js related things

Advanced CSS/JS Aggregation Module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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