Friday, November 6, 2009


Through HTTP compression a web application performance will increase tremendously
(depending on the browser support).
In PHP / ColdFusion this is built in and can be done using popular plug-in like Combine and Minify.
In ASP.NET this can be achieved by either configuring the IIS, or modifying the Global.asax file. There is an online tool available to check the compressionClick here online tool
Rate of compression is more means faster response, less bandwidth, and a more satisfied end-user!! But take care while using this in AJAX application. Better don’t go for it.

void Application_PreRequestHandlerExecute(object sender, EventArgs e)
HttpApplication app = sender as HttpApplication;
string acceptEncoding = app.Request.Headers["Accept-Encoding"];
Stream prevUncompressedStream = app.Response.Filter;
if (!(app.Context.CurrentHandler is Page app.Context.CurrentHandler.GetType().Name == "SyncSessionlessHandler")
app.Request["HTTP_X_MICROSOFTAJAX"] != null)
if (acceptEncoding == null acceptEncoding.Length == 0)
acceptEncoding = acceptEncoding.ToLower();
if (acceptEncoding.Contains("deflate") acceptEncoding == "*")
// defalte
app.Response.Filter = new DeflateStream(prevUncompressedStream,
app.Response.AppendHeader("Content-Encoding", "deflate");
} else if (acceptEncoding.Contains("gzip"))
// gzip
app.Response.Filter = new GZipStream(prevUncompressedStream,
app.Response.AppendHeader("Content-Encoding", "gzip");

We have two compression methods. They are Deflate and GZIP. They are using the name space System.IO.Compression

No comments:

Post a Comment


Obstacles are those frightful things you see when you take your eyes off your goal.------> by Henry Ford