An HTML Minifier with Seatbelts
htmlmin is an HTML minifier that just works. It comes with safe defaults and an easily configurable set options. It can turn this:
<html>
<head>
<title> Hello, World! </title>
</head>
<body>
<p> How are <em>you</em> doing? </p>
</body>
</html>
Into this:
<html><head><title>Hello, World!</title><body><p> How are <em>you</em> doing? </p></body></html>
When we say that htmlmin has ‘seatbelts’, what we mean is that it comes with features that you can use to safely minify beyond the defaults, but you have to put them in yourself. For instance, by default, htmlmin will never minimize the content between <pre>, <textarea>, <script>, and <style> tags. You can also explicitly tell it to not minify additional tags either globally by name or by adding the custom pre attribute to a tag in your HTML. htmlmin will remove the pre attributes as it parses your HTML automatically.
It also includes a command-line tool for easy invocation and integration with existing workflows.
Source code is availble on github at https://github.com/mankyd/htmlmin:
git clone git://github.com/mankyd/htmlmin.git