{"id":3255,"library":"rcssmin","title":"rcssmin: CSS Minifier","description":"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.","status":"active","version":"1.2.2","language":"en","source_language":"en","source_url":"https://github.com/ndparker/rcssmin","tags":["CSS","minifier","web development","performance","frontend"],"install":[{"cmd":"pip install rcssmin","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Runtime dependency for the Python implementation.","package":"python","optional":false},{"reason":"Common build-time dependency for Python packages, especially those with C extensions.","package":"setuptools","optional":false},{"reason":"Required for compiling the faster C extension (rcssmin.c) during installation. If unavailable, the slower Python implementation is used.","package":"C compiler","optional":true}],"imports":[{"note":"The primary function for minifying CSS.","symbol":"cssmin","correct":"from rcssmin import cssmin"}],"quickstart":{"code":"import rcssmin\n\ncss_input = \"\"\"\\\n    /* This is a comment */\n    body {\n        color: #fff; /* inline comment */\n        font-size: 16px; /*! Important comment */\n    }\n    .container { margin: 0 auto; }\n    \"\"\"\n\n# Basic minification\nminified_css = rcssmin.cssmin(css_input)\nprint(f\"Basic Minified:\\n{minified_css}\")\n# Expected: body{color:#fff;font-size:16px}.container{margin:0 auto}\n\n# Keep 'bang comments' (comments starting with !)\nminified_with_bang = rcssmin.cssmin(css_input, keep_bang_comments=True)\nprint(f\"\\nMinified with Bang Comments:\\n{minified_with_bang}\")\n# Expected: body{color:#fff;font-size:16px/*! Important comment */}.container{margin:0 auto}","lang":"python","description":"This example demonstrates basic CSS minification and how to optionally preserve 'bang comments' (comments starting with `!`)."},"warnings":[{"fix":"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`).","message":"Installing `rcssmin` on Windows (and some other platforms) might require a C compiler (e.g., Visual C++ Build Tools) to build its faster C extension (`rcssmin.c`). Without a compiler, the installation might fall back to the slower pure Python implementation, or fail entirely if not properly handled by `pip`.","severity":"gotcha","affected_versions":"All versions with C extension (since 1.0.0)."},{"fix":"Understand `rcssmin`'s scope; for semantic optimization, integrate other tools into your build pipeline.","message":"`rcssmin` performs only *syntactical* CSS compression (e.g., stripping spaces, comments, semicolons). It does not perform *semantic* compression, such as removing empty CSS blocks, collapsing redundant properties, or short-handing properties. Users expecting deeper optimization should consider other tools or combine `rcssmin` with a semantic optimizer.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Pass `keep_bang_comments=True` to the `cssmin` function to retain desired comments.","message":"By default, `rcssmin.cssmin` removes all comments. To preserve 'bang comments' (comments starting with an exclamation mark, e.g., `/*! License */`), you must explicitly set the `keep_bang_comments=True` parameter.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your project uses Python 3.6 or a later version for compatibility and optimal performance.","message":"While older versions of `rcssmin` and its documentation might mention Python 2.7 support, the library is primarily developed and tested for Python 3.6+. Recent distribution packages have also dropped Python 2 support. For reliable and performant operation, use Python 3.6 or newer.","severity":"gotcha","affected_versions":"< 1.0.6 (Python 2.7, 3.6+); >= 1.0.6 (Python 3.6+ recommended)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}