RCSSmin is a CSS minifier written in Python, based on the semantics of the YUI compressor. It prioritizes speed over maximum compression, performing syntactical compression only by removing spaces, comments, and semicolons, while supporting various CSS hacks. It includes a C re-implementation (`rcssmin.c`) that significantly improves runtime performance. The current version is 1.2.2.
pip install rcssminVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic CSS minification and how to optionally preserve 'bang comments' (comments starting with `!`).
Ensure a C compiler is available on the system, or manually force the pure Python installation if performance is not critical (e.g., `pip install --no-binary :all: rcssmin`).
Understand `rcssmin`'s scope; for semantic optimization, integrate other tools into your build pipeline.
Pass `keep_bang_comments=True` to the `cssmin` function to retain desired comments.
Ensure your project uses Python 3.6 or a later version for compatibility and optimal performance.
pip install rcssmin
Ensure the input to rcssmin.cssmin() is a string, for example: rcssmin.cssmin('body { color: red; }')Use rcssmin.cssmin() instead of rcssmin.minify_css().