############ From jsmin ############ .. package-meta:: jsmin tikitu/jsmin `jsmin `_ is the Python port of Douglas Crockford's ``jsmin``: a character-level state machine that walks the source one byte at a time and removes comments and insignificant whitespace. Like the original it does not rename a binding or fold a constant — it only deletes bytes that the tokenizer proves are optional — so its output stays close to the source size. Being a pure-Python character loop it is slow on large files, and because it tracks state by hand rather than parsing it can mishandle the regex-versus-division ``/`` in some inputs. It ships a single ``jsmin(str) -> str`` entry point and nothing else. :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 jsmin does (strip whitespace, comments and number literals) and, with its optional passes on, shrinks well past what a whitespace-only tool can reach. ******************** turbohtml vs jsmin ******************** .. list-table:: :header-rows: 1 :widths: 20 40 40 - - Dimension - turbohtml - jsmin - - Scope - Full HTML parser plus a standalone JS minifier 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 jsmin 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. - **Unparsable input raises by default.** jsmin 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 jsmin's never-fail behavior -- the source comes back verbatim instead of raising. The inline ``