jsmin

3.0.1 · maintenance · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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.")

view raw JSON →