Registry / serialization / jsmin
library3.0.1pypypi✓ verified 22d ago

jsmin is a Python library and command-line tool for minifying JavaScript code, based on Douglas Crockford's original jsmin.c. It removes unnecessary whitespace and comments to reduce file size. The current version is 3.0.1. The project is actively maintained, though the maintainer has stated they do not intend to add ECMAScript 6 (ES6) compatibility, indicating a focused maintenance cadence for its existing feature set.

pip install jsmin
INSTALL
IMPORT
SIG · JSMIN
J
jsmin
serializationpythonv3.0.1
Install
2.4s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.1 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

jsmin
from jsmin import jsmin

Minify a JavaScript string directly, or read from a file, process, and print the minified output. The primary function `jsmin()` takes a string of JavaScript code and returns the minified version.

from jsmin import jsmin js_code = ''' // This is a comment function greet(name) { console.log("Hello, " + name + "!"); } greet("World"); ''' minified_js = jsmin(js_code) print(minified_js) # Example with a file (hypothetical, requires myfile.js to exist) # try: # with open('myfile.js', 'r') as js_file: # minified_from_file = jsmin(js_file.read()) # print(minified_from_file) # except FileNotFoundError: # print("myfile.js not found for file example.")
jsmin --version
Debug
Known issues
breakingVersion 3.0.0 removed support for Python 2. If you require Python 2 compatibility, you must use version 2.2.2.
fix
Upgrade to Python 3 or pin `jsmin` to version `2.2.2` for Python 2 projects: `pip install 'jsmin==2.2.2'`.
affects: 3.0.0+
gotcha`jsmin` does not attempt to be compatible with ECMAScript 6 (ES6 / ES.next / Harmony) syntax. Using it on modern JavaScript code may result in incorrect minification or errors.
fix
Ensure your JavaScript input is compatible with older ECMAScript standards (ES5-ish) or consider alternative minifiers for ES6+ code. For specific cases like template literals or certain quoted strings, the `quote_chars` parameter might offer limited help: `jsmin(code, quote_chars="'\"`")`.
affects: All versions
gotcha`jsmin` expects syntactically correct JavaScript as input. Providing invalid JavaScript may lead to minification failures or corrupted output.
fix
Always validate your JavaScript code using a linter or by running it in an environment (like a browser or Node.js) before feeding it to `jsmin`.
affects: All versions
gotchaComments starting with `/*!` (often called 'loud comments' or 'licence comments') are preserved during the minification process since version 2.2.0. Other comments are stripped.
fix
Be aware of this behavior when expecting all comments to be removed. Use `/*!` for comments you wish to retain (e.g., copyright notices).
affects: 2.2.0+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'jsmin'
The `jsmin` Python package has not been installed in your current environment.
fix
Install the package using pip: `pip install jsmin`
Error: JSMIN unterminated comment
The input JavaScript code contains a syntax error such as an unclosed `/*` comment block, an unterminated string literal, or an unterminated regular expression literal, which `jsmin` detects.
fix
Correct the syntax errors in your JavaScript file, specifically ensuring all comments, string literals, and regular expression literals are properly terminated. For example, close `/*` with `*/`, ensure strings have matching quotes, and regexes have closing `/`.
SyntaxError: Invalid or unexpected token
The `jsmin` library (version 3.0.1) does not support ECMAScript 6 (ES6) or newer JavaScript syntax, and attempting to minify such code can lead to parsing errors during or after minification.
fix
Ensure the input JavaScript adheres to older ECMAScript standards (pre-ES6) or consider using a different minifier that supports modern JavaScript. If some ES6 features are used, experimenting with the `quote_chars="'` parameter might help in very specific cases, but full ES6 compatibility is not guaranteed.
Upgrade
Version history
3.0.1latest on PyPI · released Jan 16, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
18
Google (search)
1
Resources
jsmin — pip install jsmin · libregistry