Aggregate and compress drupal 7 CSS files

When checking the configuration window for:

Compile and compress the CSS files, it says that it was saved successfully, but the parameter does not remain set, and the css files are NOT compressed into one file. Why is this. (Using drupal 7)

+4
source share
3 answers

I assume that since you are not mentioning this, does javascript aggregation work?

Drupal CSS aggregation does not parse CSS (now), it just executes some regular expressions before combining files, so it can break if it encounters valid but unusually formatted CSS, or trivially incorrect CSS syntax that you would never have noticed otherwise.

Check out any custom CSS that you made for any CSS bugs or quirks (something unusual), as well as any non-body modules or themes that the CSS buggies might have.

To give you an idea, some of the things that caused the problems include

It might also be worth checking that the file encodings are consistent. In particular, there is one well-known source of strange results in the aggregation of feeds and UTF8 byte-marker (BOM) files that may erroneously leak into files. Here's a command that removes the entire specification from all files in a directory (use with caution!).

If JS aggregation does not work either , it is almost certainly a problem with the server or directory - check the permissions of the file files, check for the appropriate compression libraries and everything that Duncan mentions.

If nothing works, you can try the agrcache module or the Core Library module . They modify the methods used by aggregation, and may give different results or clues regarding the problem. And watch out for aggregation issues for Drupal 7 as well as Drupal 8 - there may be problems in the problems that people are working on.

+3
source

If your directory of temporary files is not configured, then aggregated CSS (and JS) files cannot be written out, and I believe this option will turn off again. Sometimes this happens due to incorrect path settings for this directory. In other cases, the path is set correctly, but there are problems with permissions in the directory, which mean that the web server cannot write to this path. In any case, this prevents aggregation from working.

Another thing you can do is check your site’s log for error messages that may indicate the source of the problem.

+2
source

This is the solution .

Stylesheets

<?php function THEME_css_alter(&$css) { // Sort CSS items, so that they appear in the correct order. // This is taken from drupal_get_css(). uasort($css, 'drupal_sort_css_js'); // The Print style sheets // I will populate this array with the print css (usually I have only one but just in case…) $print = array(); // I will add some weight to the new $css array so every element keeps its position $weight = 0; foreach ($css as $name => $style) { // I leave untouched the conditional stylesheets // and put all the rest inside a 0 group if ($css[$name]['browsers']['!IE']) { $css[$name]['group'] = 0; $css[$name]['weight'] = ++$weight; $css[$name]['every_page'] = TRUE; } // I move all the print style sheets to a new array if ($css[$name]['media'] == 'print') { // remove and add to a new array $print[$name] = $css[$name]; unset($css[$name]); } } // I merge the regular array and the print array $css = array_merge($css, $print); } ?> 

Scenarios

 <?php function THEME_js_alter(&$js) { // Sort JS items, so that they appear in the correct order. uasort($js, 'drupal_sort_css_js'); $weight = 0; foreach ($js as $name => $javascript) { $js[$name]['group'] = -100; $js[$name]['weight'] = ++$weight; $js[$name]['every_page'] = 1; } } ?> 
+1
source

Source: https://habr.com/ru/post/1380850/


All Articles