Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

deanhume/html-minifier

Repository files navigation

HTML Minifier

A fast and efficient command-line tool to minify your HTML, Razor views, and Web Forms views. Reduce file sizes, improve load times, and deliver a better user experience by removing unnecessary whitespace and comments from your HTML files.

Features

  • Fast Processing - Minifies files and entire directory trees quickly
  • Flexible Input - Process individual files, specific folders, or entire directory structures
  • Configurable - Control line length and selectively disable minification features
  • Framework Support - Special handling for Knockout.js, Angular, and other comment-dependent frameworks
  • Targeted Minification - Choose what to minify: HTML comments, JavaScript comments, or Knockout comments
  • CI/CD Ready - Easy integration with MSBuild and build pipelines

Installation

  1. Download the latest release from the releases page
  2. Extract the HtmlMinifier.exe to your desired location
  3. Add the tool to your PATH or reference it directly

Quick Start

Transform verbose HTML into compact, optimized code:

Before:

<h2>
Admin Menuh2>
<ul>
<li>@Html.ActionLink("Edit blog entries", "List", "Admin")li>
<li>@Html.ActionLink("View Comments", "CommentList", "Admin")li>
<li>@Html.ActionLink("Clear Cache", "ClearCache", "Admin")li>
ul>

After:

<h2> Admin Menuh2><ul><li>@Html.ActionLink("Edit blog entries", "List", "Admin")li><li>@Html.ActionLink("View Comments", "CommentList", "Admin")li><li>@Html.ActionLink("Clear Cache", "ClearCache", "Admin")li>ul>

Usage

Basic Usage

Minify all HTML files in a folder (including subfolders):

HtmlMinifier.exe "C:\Folder"

Advanced Options

Limit Line Length

Restrict the maximum number of characters per line:

HtmlMinifier.exe "C:\Folder" "60000"

Preserve Comments

For frameworks that rely on HTML comments (Angular, Knockout, etc.), preserve them:

HtmlMinifier.exe "C:\Folder" ignorehtmlcomments

Preserve JavaScript Comments

Keep JavaScript comments in your code:

HtmlMinifier.exe "C:\Folder" ignorejscomments

Preserve Knockout Comments

Specifically preserve Knockout.js comments:

HtmlMinifier.exe "C:\Folder" ignoreknockoutcomments

Multiple Targets

Minify Multiple Folders

HtmlMinifier.exe "C:\Folder\fld1" "C:\Folder\fld2"

Minify Specific Files

HtmlMinifier.exe "C:\Folder\file1.html" "C:\Folder\file2.html"

Build Integration

Integrate HTML Minifier into your build process for automatic minification during deployment. Check out this detailed guide on using HTML Minifier with MSBuild.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Requirements

  • .NET Framework (Windows)
  • Supports HTML, Razor (.cshtml), and Web Forms (.aspx) files

License

Copyright (C) Dean Hume 2013 - 2025

Released under the MIT License


Made with by Dean Hume

About

A simple command line tool to minify your HTML, Razor views & Web Forms views

Topics

Resources

Readme

License

MIT license

Stars

Watchers

Forks

Packages

Contributors

Languages