Skip to content
HTML Minification of ASP.NET Razor views
Branch: master
Clone or download
Latest commit 4d1dfbc Nov 11, 2013
Type Name Latest commit message Commit time
Failed to load latest commit information.
Meleze.sln Prepare the 1.4.4 release Aug 30, 2013
build.proj Enhance the minification engine: Mar 17, 2012


To use the HTML Minification for Razor, you have to change your Views/Web.config to replace the default ASP.NET MVC factory by the Meleze's one:

    <host factoryType="Meleze.Web.Razor.MinifyHtmlWebRazorHostFactory, Meleze.Web, Version=, Culture=neutral, PublicKeyToken=0a868b5321967eda" />

For ASP.NET MVC 3.0, use the 1.3 version of Meleze:
    <host factoryType="Meleze.Web.Razor.MinifyHtmlWebRazorHostFactory, Meleze.Web, Version=, Culture=neutral, PublicKeyToken=0a868b5321967eda" />

There are two versions of the DLL: one for ASP.NET MVC3 and another for ASP.NET MVC4. Make sur to use the correct version (it is displayed in the DLL description).

Making this change in the Web.config may break Intelliscense in Visual Studio if it does not find the Meleze.Web dll.
There are two solutions:
1) You can setup the factory in Web.config.Release instead of the Web.config. The minification will be enabled only in release build.
2) Otherwize, you can register the Meleze.Web dll in the GAC using "gacutil.exe -i Meleze.Web". The minification will work even in design mode.

The Minifier behavior can be configured in the application's root Web.config with some appSettings keys:

  <add key="meleze-minifier:Aggressive" value="true"/>
  <add key="meleze-minifier:Comments" value="true"/>
  <add key="meleze-minifier:Javascript" value="true"/>
  <add key="meleze-minifier:CSS" value="true"/>

meleze-minifier:Aggressive removes as much whitespace as possible. In some cases, you may have to change yours CSS to fix the page layout (as whitespace is not interpreted in a compatible way by all browsers).
meleze-minifier:Comments removes all the HTML comments that are neither Javascript code or conditional comments.
meleze-minifier:Javascript calls the Microsoft Ajax Minifier. The AjaxMin.dll must be in the application references for this option to work (otherwise, JS is kept as is).
meleze-minifier:CSS also calls the Microsoft Ajax Minifier to minimize the inline styles.

There is also a NuGet package to setup the Minifier automatically in your applications.

You can find more details in

- 1.4.6 and 1.3.6 (11/11/2013)
    - Fix integration with Microsoft AjaxMin (from SoonDead)
    - Fix minification of URL starting with ~/

- 1.4.5 and 1.3.5 (10/11/2013)
    - Fix integration with System.Web.Optimization
    - Add minification of the Razor sections

- 1.4.4 and 1.3.4 (30/08/2013)
    - Fix bugs with the detection of Javascript // comments.
    - Minify the inline JS and CSS with the System.Web.Optimization if it is available.

- 1.4.3 and 1.3.3 (4/24/2012)
    - Fix bug when inline Javascript contains // comments and that the Javascript minifier is not enabled.
    - Minify the inline CSS with the Microsoft Ajax Minifier (like for the inline Javascript).
You can’t perform that action at this time.