korpress¶
korpress makes your HTML, CSS and JavaScript files smaller. This is called minifying: it removes the comments and spaces that a browser does not need, so the files load faster and mean the same thing. It is a Python library with a command line, written in Rust, and it is fast.
After installing it, minify a piece of CSS:
import korpress
korpress.minify_css("a { color : red ; margin : 0px }") # 'a{color:red;margin:0}'
The spaces are gone, and 0px became 0, which means the same. If you are
new to this, the tutorial takes you from a few strings to a
whole site, step by step.
Install¶
Python 3.10 and later. Only alphas are published, so pass --pre:
pip install --pre korpress
More examples¶
Each kind of code has its own function, and minify_file works on a file:
korpress.minify_js("var a = 1 ; // hi\nvar b = a + 1") # 'var a=1;var b=a+1'
korpress.minify_html("<div>\n <p> Hello <b>you</b> </p>\n</div>") # '<div><p>Hello <b>you</b></p></div>'
korpress.minify_file("app.css", "app.min.css") # returns (bytes_before, bytes_after)
From the shell, the same job is one command: korpress site/ -o dist/. See
Command line.
Where to start¶
- New here? Follow the tutorial: minify a small site step by step.
- Command line:
korpress site/ -o dist/. - Guide: HTML, CSS, JavaScript, and limits and safety.
- With Korvex and from Rust.
- Glossary and for AI assistants.
- Reference: every public name, built from the docstrings.
- Source code and changelog.
In depth¶
Status¶
Alpha. The API may change before 1.0. The three minifiers are written by hand, with no parser dependency.
What it never does¶
- No renaming. Variable, function, class and id names stay as you wrote them.
- No rewriting of what code means. There is no AST, no dead code removal, no CSS rule merging and no HTML tag omission. korpress removes what is useless, and keeps line breaks that JavaScript needs.
So the result is smaller than the source, but not as small as what a tool like terser or esbuild can give. See Limits and safety.