{"id":7117,"library":"css-html-js-minify","title":"CSS HTML JS Minifier","description":"CSS-HTML-JS-Minify is a standalone, asynchronous, cross-platform, and Unicode-ready Python 2 and 3 library for minifying web assets (CSS, HTML, JavaScript). It can process single files or entire folders, offering features like GZIP compression, SHA1 hashing for filenames, and optional alphabetical sorting of CSS properties. The current version is 2.5.5, last updated in 2018, indicating a maintenance-oriented release cadence.","status":"maintenance","version":"2.5.5","language":"en","source_language":"en","source_url":"https://github.com/juancarlospaco/css-html-js-minify#css-html-js-minify","tags":["minifier","css","html","js","javascript","web","build-tool"],"install":[{"cmd":"pip install css-html-js-minify","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"process_single_html_file","correct":"from css_html_js_minify import process_single_html_file"},{"symbol":"process_single_js_file","correct":"from css_html_js_minify import process_single_js_file"},{"symbol":"process_single_css_file","correct":"from css_html_js_minify import process_single_css_file"},{"symbol":"html_minify","correct":"from css_html_js_minify import html_minify"},{"symbol":"js_minify","correct":"from css_html_js_minify import js_minify"},{"symbol":"css_minify","correct":"from css_html_js_minify import css_minify"}],"quickstart":{"code":"from css_html_js_minify import (html_minify, js_minify, css_minify,\n                                  process_single_html_file, process_single_js_file)\n\n# Minify strings\nminified_html = html_minify(' <p>yolo<a href=\"/\" >o </a > <!-- hello --></p>')\nprint(f\"Minified HTML string: {minified_html}\")\n\nminified_js = js_minify('var i = 1; i += 2 ;\\n alert( \"hello \" ); //hi')\nprint(f\"Minified JS string: {minified_js}\")\n\nminified_css = css_minify('body {width: 50px;}\\np {margin-top: 1em;/* hi */ }', comments=False)\nprint(f\"Minified CSS string: {minified_css}\")\n\n# Example for file processing (creates dummy files first)\nwith open('test.htm', 'w') as f:\n    f.write('<html><body><!-- comment --><h1>Hello</h1></body></html>')\nwith open('test.js', 'w') as f:\n    f.write('function greet() { console.log(\"Hello\"); // Comment }')\n\nprocess_single_html_file('test.htm', overwrite=True) # Overwrites test.htm with minified content\nprocess_single_js_file('test.js', overwrite=False, output_path='test.min.js') # Creates test.min.js\n\nprint(\"Minification of test.htm and test.js completed. Check generated files.\")","lang":"python","description":"This quickstart demonstrates both string-based minification and file processing for HTML, CSS, and JavaScript. For file processing, it shows how to either overwrite the original file or create a new minified file with a specified output path."},"warnings":[{"fix":"Avoid piping input/output via standard streams. Use `process_single_..._file` functions or `..._minify` for strings.","message":"The use of Std-In to Std-Out for minification is deprecated due to potential issues with Unicode characters. It is recommended to process files directly or pass strings to the API functions.","severity":"deprecated","affected_versions":"All versions"},{"fix":"Exercise caution when using `--comments` and `--overwrite`. Consider using version control or `output_path` for backups.","message":"The CLI flags `--comments` and `--overwrite` are explicitly marked as 'Not Recommended' in the documentation. Keeping comments can reduce minification effectiveness, and overwriting files without backup can lead to data loss.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When using the Python API, pass `add_hash=True` instead of `hash=True` to enable SHA1 hashing for filenames.","message":"There is an inconsistency between the CLI argument `--hash` for adding a SHA1 hash to filenames and its Python API equivalent, which is `add_hash`. Using `hash` in the Python API will result in an error.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of the ~60-second polling interval for the `--watch` functionality; real-time updates are not supported.","message":"The `--watch` feature, which re-compresses files upon changes, operates with a minimum delay of approximately 60 seconds between runs. This means file changes might not be reflected immediately.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"The correct argument name for adding a SHA1 hash to filenames in the Python API is `add_hash`. Change `hash=True` to `add_hash=True`.","cause":"Attempting to use `hash=True` as an argument in the Python API for minification functions.","error":"AttributeError: 'module' object has no attribute 'hash'"},{"fix":"Avoid piping input/output using `sys.stdin`/`sys.stdout`. Instead, read file content directly into a string and pass it to `html_minify`, `css_minify`, or `js_minify`, or use the `process_single_..._file` functions with file paths.","cause":"Using standard input/output streams with files containing non-ASCII (Unicode) characters, which is a deprecated usage pattern for this library.","error":"UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position ..."},{"fix":"Ensure you are using `add_hash=True` (or `add_hash=False`) for the hash functionality in the Python API, not `hash`.","cause":"Passing the `hash` argument to file processing functions like `process_single_html_file` directly, or other minification functions, when `add_hash` is the expected parameter name.","error":"TypeError: process_single_html_file() got an unexpected keyword argument 'hash'"}]}