CSSTidy (released under GPL) has a PHP class to clean up CSS code. It could be easily added to common.inc on drupal_build_css_cache (patch attached). Download CSSTidy and unpack it on Drupal directory, renaming it to "csstidy".
With version 1.3 I've still some little problems on resulting CSS, but the result is reasonable. On my custom Zen subtheme the aggregated CSS file is 7KB lighter than original 47KB aggregated file. If implemented, maybe an "Clean CSS with CSSTidy" option should be provided on performance settings page.
P.S. I've seen that from Drupal 5.x to 6.x and 7.x this function lose the so called "safe CSS optimizations" via regex. Maybe can CSSTidy be a replacement to it?
| Comment | File | Size | Author |
|---|---|---|---|
| common_inc_csstidy.patch | 1.29 KB | chirale |
Comments
Comment #1
stevenpatzfeatures go in head
Comment #2
MGParisi commentedCan we make a module out of this? I think it is something that is great for drupalers...
There are other solutions to this too besides csstidy, though I find csstidy to be the best solution so far... though to use it on your hard coded css is not a wise thing to do, since it mixes everything up. The advantage of making this into a module is that it will become more visible, easier to use, etc... Depending on the type you of results you want from Tidy, you can tailor it to get better results. The one thing I noticed with csstidy, is that on large css files, it can be run over and over again on the same CSS, and you will see more and more reduction in size.
Is this even possible?
Thanks
Mike
Comment #3
donquixote commentedThe built-in CSS aggregator is buggy.
I want CSSTidy too!
Comment #4
casey commentedtagging.
we're in code freeze so this should be bumped to d8? or make this a won't fix as we just should enhance the build-in aggregator?
Comment #5
donquixote commentedIf you are only looking for a bugfix, check out
#444228: Optimize CSS option causes php cgi to segfault in pcre function "match"
Is there still a need for CSSTidy after this has been fixed in core?
If so, which hooks would a module use to replace the CSS aggregation method?
Comment #6
philbar commentedI've created an issue for this topic in CSS Embedded Images:
#747422: Help Test CSSTidy
I was able to get it working successfully. This might be an option for CSS Embedded Images or it might become an independent module.
Regardless, the hooks that are required, are already used in CSS Embedded Images.
Comment #7
philbar commentedThere is now a module for this:
http://drupal.org/project/csstidy