ASP.NET - How to optimize ASP.Net website by using GZip aspx compression?

Asked By RAJESH VEMUNOORI on 22-Mar-13 04:41 AM
Hi All,

I have built an ASP.Net website which uses JAVA webservice in order to access database procedures. My problem is, the pages take much time to load. I have tracked the time taking to call web service, but found it takes a few milliseconds. On tracing the load time of the page by using some web developer tools provided by latest browser versions, I found that larger the content of the page, more would be the load time.
   After some googling I found Gzip provides aspx compression which reduces content length of aspx pages..Can any one suggest the exact steps to use it..?


Appreciate your help.

Regards,
Rajesh.
Robbe Morris replied to RAJESH VEMUNOORI on 22-Mar-13 09:02 AM
You do this in IIS not your ASP.NET code.
RAJESH VEMUNOORI replied to Robbe Morris on 25-Mar-13 03:03 AM
Hello Robbe,

I could do this process by the following process..

 if (contentType == "text/html" || contentType == "text/css" || contentType == "text/js")
      {
        // Get the Accept-Encoding header value to know whether zipping is supported by the browser or not.
        string acceptEncoding = Request.Headers["Accept-Encoding"];

        if (!string.IsNullOrEmpty(acceptEncoding))
        {
          // If gzip is supported then gzip it else if deflate compression is supported then compress in that technique.
          if (acceptEncoding.Contains("gzip"))
          {
            // Compress and set Content-Encoding header for the browser to indicate that the document is zipped.
            Response.Filter = new GZipStream(Response.Filter, CompressionMode.Compress);
            Response.AppendHeader("Content-Encoding", "gzip");
          }
          else if (acceptEncoding.Contains("deflate"))
          {
            // Compress and set Content-Encoding header for the browser to indicate that the document is zipped.
            Response.Filter = new DeflateStream(Response.Filter, CompressionMode.Compress);
            Response.AppendHeader("Content-Encoding", "deflate");
          }
        }
      }


I've added the above code in a class file and inherited to global.asax.


-Rajesh
Robbe Morris replied to RAJESH VEMUNOORI on 25-Mar-13 08:53 AM
Sure but why force your code to do this when IIS can automatically handle for all content types that it supports?
RAJESH VEMUNOORI replied to Robbe Morris on 25-Mar-13 12:31 PM
You are right.. but my site is hosted on the server of which I don't have access for these settings..