How to Minify HTML output from ASP.NET MVC

This post shows you how to minify HTML in ASP.NET MVC or ASP.NET Web Forms. To make your site load faster, you should minimize downloads of resources.

You can use to  check the performance of your websites

First you need to download Minifier Html tool from

This is a simple command line tool to minify your HTML, Razor views & Web Forms views. By minifying your HTML on bigger web pages, you'll save on bytes that your clients need to download.

Open Properties->PublishProfiles->Open your pubxml extension file

Add HtmlMinifier.exe to your publishing profile

<?xml version="1.0" encoding="utf-8"?>
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit 
<Project ToolsVersion="4.0" xmlns="">
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
  <Target Name="CustomAction" AfterTargets="CopyAllFilesToSingleFolderForPackage">
    <Message Text="Minifying files....." />
    <Exec Command="D:\Publish\HtmlMinifier.exe $(_PackageTempDir)" IgnoreExitCode="true" />

Note: Copy HtmlMinifier.exe to your publishing project directory, then publish your project

For example: Original html file

    <li>@Html.ActionLink("Home", "Index", "Home")</li>

After Minifying the html file

<h2></h2><ul><li>@Html.ActionLink("Home", "Index", "Home")</li></ul>

I hope you can optimize your site's performance by using the HtmlMinifier tool