glib-compile-resources: Add preprocessor to minify CSS
@dboles
Submitted by Daniel Boles Link to original bug (#783148)
Description
g-c-r already provides the xml-stripblanks option for the preprocess attribute, widely used to compress .ui files before embedding tem in the binary.
Another common type of file put into GResources is CSS files. Like .ui files, often a substantial portion of their content is technically useless whitespace, comments, etc. Using the compress attribute helps, but it still has to compress all the cruft, and decompressing it takes extra time (probably not really an issue). Either way, the performance would be better if there was less to store.
Currently, to get rid of the unnecessary and bloaty content in the GResource, we must use an external tool to strip the original CSS files and then compile the result of that. This requires a pile of extra stuff in the build system files.
So it would be great if g-c-r itself had a built-in preprocessing option to strip superfluous content from CSS files before putting them in the GResource.
As a reference, at the moment I use yui-compressor - http://yui.github.io/yuicompressor/
- which removes the following:
- whitespace
- comments
- the final semicolon in any block
- reduces 6-digit colours like #003366 down to #36
- trailing units on 0 quantities (IIRC), e.g. 0px => 0
I believe yui-compressor doesn't, but that leading zeros in decimal numbers can also be omitted: http://hey.georgie.nu/leadingzero/
A lot of this would boil down to simple regex removals, though I've not sat down and worked through it yet; possibly some parts are not so simple. But an example set of replacements of this form is shown here: http://madskristensen.net/post/efficient-stylesheet-minification-in-c