Registry / devops / css-html-js-minify

css-html-js-minify

JSON →
library2.5.5pypypi✓ verified 86d ago

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.

pip install css-html-js-minify
INSTALL
IMPORT
SIG · CSS-HTML-JS-MINIFY
C
css-html-js-minify
devopspythonv2.5.5
Install
1.5s avg
Import
72ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.078s · 17.9MB
glibc
py 3.103.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
Debug
Known issues
deprecatedThe 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.
fix
Avoid piping input/output via standard streams. Use `process_single_..._file` functions or `..._minify` for strings.
affects: All versions
gotchaThe 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.
fix
Exercise caution when using `--comments` and `--overwrite`. Consider using version control or `output_path` for backups.
affects: All versions
gotchaThere 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.
fix
When using the Python API, pass `add_hash=True` instead of `hash=True` to enable SHA1 hashing for filenames.
affects: All versions
gotchaThe `--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.
fix
Be aware of the ~60-second polling interval for the `--watch` functionality; real-time updates are not supported.
affects: All versions
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.
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`.
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.
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.
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.
fix
Ensure 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.

Agent activity
12 hits · last 30 days
node
10
Resources
css-html-js-minify — pip install css-html-js-minify · libregistry