rjsmin: Fast Javascript Minifier for Python

1.2.5 · active · verified Fri Apr 10

rJSmin is a javascript minifier written in Python, based on the semantics of jsmin.c by Douglas Crockford. It is a re-implementation aiming for speed, designed for runtime use rather than a preprocessing step, and usually produces the same results as the original `jsmin.c`. The current version is 1.2.5 and it supports Python 2.7 and 3.6+.

Warnings

Install

Imports

Quickstart

The `jsmin` function takes a string containing JavaScript code and returns its minified version as a string. An optional `keep_bang_comments` parameter allows preserving comments starting with an exclamation mark.

from rjsmin import jsmin

js_code = """\
function hello( name ) {
    /* a comment */
    return 'Hello, ' + name + '!';
}
"""

minified_code = jsmin(js_code)
print(minified_code)
# Expected output: function hello(name){return'Hello,'+name+'!'}

view raw JSON →