Install & Compatibility
Where this runs
tested against v2.5.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.078s · 17.9MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.067s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
process_single_html_file
✓ from css_html_js_minify import process_single_html_file
process_single_js_file
✓ from css_html_js_minify import process_single_js_file
process_single_css_file
✓ from css_html_js_minify import process_single_css_file
html_minify
✓ from css_html_js_minify import html_minify
js_minify
✓ from css_html_js_minify import js_minify
css_minify
✓ from css_html_js_minify import css_minify
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.
from css_html_js_minify import (html_minify, js_minify, css_minify,
process_single_html_file, process_single_js_file)
# Minify strings
minified_html = html_minify(' <p>yolo<a href="/" >o </a > <!-- hello --></p>')
print(f"Minified HTML string: {minified_html}")
minified_js = js_minify('var i = 1; i += 2 ;\n alert( "hello " ); //hi')
print(f"Minified JS string: {minified_js}")
minified_css = css_minify('body {width: 50px;}\np {margin-top: 1em;/* hi */ }', comments=False)
print(f"Minified CSS string: {minified_css}")
# Example for file processing (creates dummy files first)
with open('test.htm', 'w') as f:
f.write('<html><body><!-- comment --><h1>Hello</h1></body></html>')
with open('test.js', 'w') as f:
f.write('function greet() { console.log("Hello"); // Comment }')
process_single_html_file('test.htm', overwrite=True) # Overwrites test.htm with minified content
process_single_js_file('test.js', overwrite=False, output_path='test.min.js') # Creates test.min.js
print("Minification of test.htm and test.js completed. Check generated files.")
css-html-js-minify --version
Errors
Common errors & fixes
AttributeError: 'module' object has no attribute 'hash'
Attempting to use `hash=True` as an argument in the Python API for minification functions.
fixThe correct argument name for adding a SHA1 hash to filenames in the Python API is `add_hash`. Change `hash=True` to `add_hash=True`.
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position ...
Using standard input/output streams with files containing non-ASCII (Unicode) characters, which is a deprecated usage pattern for this library.
fixAvoid 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.
TypeError: process_single_html_file() got an unexpected keyword argument 'hash'
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.
fixEnsure you are using `add_hash=True` (or `add_hash=False`) for the hash functionality in the Python API, not `hash`.
Upgrade
Version history
2.5.5latest on PyPI · released Apr 14, 2018
Audit
Dependencies
No dependency data recorded yet.