2

I have a asp.Net MVC 4 projects .In My project only render big reports (use table html element) So I have a considering : Should I remove white space when running like as How can I remove white-spaces from ASP.NET MVC# output? or Remove all white space when I write html code .it' mean I will manually remove all white space in visual studio before deploying

Everybody help me?

Community
  • 1
  • 1
Alex Nguyen
  • 1,032
  • 12
  • 27

1 Answers1

1

I guess that you are trying to get answer if the run-time solution (described in the link) won't be an issue in production, right? Well, as mentioned here:

Memory Efficiency and Performance of String.Replace .NET Framework

you should do some own benchmarking. To be sure, that replacing chars of a big report for many users won't kill the performance.

But my suggestion is do it in run-time. Maybe better in AOP filter. At once, when all the response is finished (I am doing similar functionality replacing some strings).

public virtual void OnResultExecuted(ResultExecutedContext filterContext)
{
  // Change result as needed
  filterContext.HttpContext.Response.Filter = 
    new ResponseStream(filterContext.HttpContext.Response.Filter);
}

And here is the Stream

protected class ResponseStream : MemoryStream
{
    readonly Stream _stream;
    public ResponseStream(Stream stream)
    {
        _stream = stream;
    }

    public override void Write(byte[] buffer, int offset, int count)
    {
        //base.Write(buffer, offset, count);
        string html = System.Text.Encoding.Default.GetString(buffer);

        // TODO - here remove spaces...

        byte[] outdata = System.Text.Encoding.Default.GetBytes(html);

        //write bytes to stream
        _stream.Write(outdata, 0, outdata.GetLength(0));
    }
}

The second think, could be enabling of the dynamic compression on your IIS (if using IIS 7.0 please read http://technet.microsoft.com/en-us/library/cc753681%28v=ws.10%29.aspx)

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335