title: Removing extra whitespace from generated HTML in MVC
body: <p>I have an MVC application view that is generating quite a large HTML table of values (>20MB).</p>
  
  <p>I am compressing the view in the controller using a compression filter</p>
  
  <pre><code> internal class CompressFilter : ActionFilterAttribute
   {
       public override void OnActionExecuting(ActionExecutingContext filterContext)
       {
           HttpRequestBase request = filterContext.HttpContext.Request;
           string acceptEncoding = request.Headers["Accept-Encoding"];
           if (string.IsNullOrEmpty(acceptEncoding))
               return;
           acceptEncoding = acceptEncoding.ToUpperInvariant();
           HttpResponseBase response = filterContext.HttpContext.Response;
           if (acceptEncoding.Contains("GZIP"))
           {
               response.AppendHeader("Content-encoding", "gzip");
               response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
           }
           else if (acceptEncoding.Contains("DEFLATE"))
           {
               response.AppendHeader("Content-encoding", "deflate");
               response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
           }
       }
   }
  </code></pre>
  
  <p>Is there a way to also eliminate the (quite large) amount of redundant whitespace generated in the view before I run the compress filter (to reduce compression workload and size)?</p>
  
  <p><b>EDIT:</b>
  I got it working using the WhiteSpaceFilter technique suggested by Womp below.</p>
  
  <p>For interest here's the results, as analysed by Firebug:</p>
  
  <p>1) No Compression, no whitespace strip - 21MB, 2.59 minutes<br/>
  2) With GZIP compression, no whitespace strip - 2MB, 17.59s<br/>
  <b>3) With GZIP compression, whitespace strip - 558kB, 12.77s</b>
  <br/>
  <br/>
  So certainly worth it.</p>