Take the 2-minute tour ×

This is likely a duplicate of the below question but the only answer is a dead link:

When working with ASP.Net one of the more annoying aspects to me is the fact that Visual Studio puts spaces instead of tabs for white spacing which increases the size of the final HTML. I originally thought of simply changing Visual Studio settings to use tabs instead but then others on my team will still end up overlaying with spaces anyway.

My question is two fold: first is there a way to on a per project setting to change if spaces or tabs are used (and is it even worthwhile if so) and second, is there a way to simply minify all of the views when generated?

share|improve this question
add comment

3 Answers

up vote 27 down vote accepted

Enabling GZIP will have much more effect than minifying your HTML, anyway.

share|improve this answer
+1. You should be compressing your output on transfer anyway, and when you are then a tab and a few spaces will take effectively the same bandwidth. –  bobince Jan 20 '10 at 20:32
Where would the two Filters go inside the MVC folder hierarchy? –  Maxim Zaslavsky Apr 2 '10 at 1:10
add comment

I agree that the gzip response is the 'right' strategy. To answer your question, though, the easiest thing would be to get or make a simple executable for stripping whitespace, and then putting that into your project's build as a custom build step. this article : http://encosia.com/2009/05/20/automatically-minify-and-combine-javascript-in-visual-studio/ talks about doing that when minimizing and combining javascript, but the same technique would work for views.

share|improve this answer
Visual studio actually allows to find/replace using regex. So, you can find all \s{8} and replace them with \t (dunno if such syntax works, but something similar would) –  naivists Jan 20 '10 at 20:30
of course, but that's still a manual step. That's why I suggest doing it in the build step. –  Paul Jan 21 '10 at 17:37
Thanks, this is extremely helpful!! –  mynameiscoffey Jan 22 '10 at 6:04
I don't like the regex solution in VS because it will make my development code unreadable. The best would be to see the expanded source at development time and then get the build to do the minification for output. –  orad Mar 13 '13 at 17:38
add comment

This link works (from the related link that you provide). It has a solution that let you replace the WebRazorHostFactory by one that minifies your HTML.

To make it work, you have to add the following in your Web.config file:

  <host factoryType="Omari.Web.Mvc.WhiteSpaceCleaningMvcWebRazorHostFactory, WhiteSpaceCleanerForWebFormsAndMVC3" />

This section is usually placed into Views\Web.config.

share|improve this answer
Does not work with MVC4. See github.com/Chebur9tina/HtmlOptimizerMvc4 if your need MVC4 support –  Cheburek Oct 23 '13 at 13:55
add comment

Your Answer


