HTMLMinifier is a highly configurable, well-tested, JavaScript-based HTML minifier. See corresponding blog post for all the gory details of how it works, description of each option, testing results ...