mincss - CSS Minifier
mincss is a small CSS minifier written as a POSIX compliant shell script.
The CSS on this site has been minified with mincss. Feel free to compare the files before minification and after minification.
Usage
From a terminal:
mincss input-file [output-file]
- If output-file is omitted, the minified CSS will be echoed to stdout.
-
If output-file is specified, the minified CSS will be written to that file
and a short status message will be echoed to stdout, for example:
Trimmed 292 bytes (19.2358% smaller)
Download
Notes
I got the idea that I wanted to minify my (already small) CSS for this site, and figured a small command line tool would do the job. Alas, all the command line tools I could find in the regular places (and without overstretching my google-fu) required some combination of Python or Node.js, which seemed excessive considering I basically just wanted to strip away a few whitespaces here and there.
Needless to say, CSS minification can be a lot more intricate than stripping away spaces using a few rudimentary regular expressions, but for my needs (and for the various stylesheets I've tested with), mincss does the job.
- No validation takes place - input is assumed to be valid CSS.
- Comments and (most) whitespace will be stripped.
- Testing has taken place with moderately complex CSS files, from (among others) pouet.net, news.ycombinator.com and jigsaw.w3.org.
- The script has been linted with shellcheck.
- The script probably has bugs.