A regex-based {JavaScript,CSS,HTML,...} minifier
Python
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.markdown
gordian_minifier.py

README.markdown

gordian-minifier

Automatic hardcore minification is a hard problem, especially when you want to jointly minify muiltiple types of things (e.g. a large set of JavaScript and CSS and HTML files).

gordian-minifier slices that knot by simply using a regex.

Each name that matches a regex is replaced by the shortest available alphabetic string not occuring anywhere in the code so far.

This is done in order of long-name frequency, so your most frequent long names get dibs on the shortest available strings.

Long-name Exemptions

You can explicitly exempt some long names from being minified.

Minifying Multiple Files

Your build script can concatenate them, use findMapping, and apply that mapping to each file.

Python usage

from gordian_minifier import minify, findMapping

# This
code = minify(code, regex=..., exemptions=[...])

# ...is equivalent to this
mapping = findMapping(code, regex=..., exemptions=[...])
for src, dest in mapping.items():
  code = code.replace(src, dest)

Command-line usage

... | python gordian-minifier.py | ...
... | python gordian-minifier.py
                        --regex=...
                        --exemptions=_foo,_bar,... | ...

Default Regex

DEFAULT_REGEX = r'''(?x)
    [^a-zA-Z_](
        (?:_[a-zA-Z0-9_]+)|
        (?:[a-zA-Z_][a-zA-Z0-9_]*_CSS))'''
_example
AnotherExample_innerDiv_CSS