############# From rjsmin ############# .. package-meta:: rjsmin ndparker/rjsmin `rjsmin `_ minifies JavaScript with a single regular-expression substitution: one pass strips comments and insignificant whitespace and nothing else. It ships a compiled ``_rjsmin`` speedup with a pure-Python fallback, so the regex runs fast even on large files, and it is a common build-step dependency where the only goal is to drop bytes the tokenizer proves are optional. Because a regex never renames a binding or folds a constant, the output stays close to the source size. Its whole surface is one function, ``jsmin(script, keep_bang_comments=False) -> str``, where ``keep_bang_comments`` preserves ``/*! ... */`` license blocks. :func:`~turbohtml.clean.minify_js` covers the same ground with a real front end: it lexes and parses to an arena AST in C, renames function-local bindings, folds constants, and prints the result. It always does at least what rjsmin does (strip whitespace and comments) and, with its optional passes on, shrinks well past what a whitespace-only substitution can reach. The HTML-embedded case rjsmin leaves to you — it only ever sees a script string you extract — is built in: pass a :class:`~turbohtml.clean.JSMinify` as :class:`~turbohtml.Minify`'s ``minify_js`` and inline ``") doc.serialize(Html(layout=Minify(minify_js=JSMinify()))) ********************** Gotchas and pitfalls ********************** - **Renaming is on by default.** ``turbohtml.clean.minify_js(source)`` renames local bindings, which rjsmin never does. If a consumer reflects on function-local variable names (rare), pass ``JSMinify(mangle=False)``. Top-level names are global and are never renamed regardless of the setting. - **License banners are kept, not stripped, and hoisted to the top.** turbohtml keeps ``/*! ... */`` and ``@license`` / ``@preserve`` comments byte-exact and emits them as a leading banner in source order, while dropping every other comment. rjsmin only keeps them under ``keep_bang_comments=True`` and leaves them in place, so a diff against rjsmin output differs when a bang comment sits mid-script. - **Unparsable input raises by default.** rjsmin emits something for any string; the standalone :func:`~turbohtml.clean.minify_js` raises :class:`ValueError` on a construct its parser does not handle. Pass ``on_error="passthrough"`` for rjsmin's never-fail behavior -- the source comes back verbatim instead of raising. The inline ``