Tuesday, October 10, 2006

Quick and dirty solution for compression.

This is a real cheap solution in terms of http compression.Just to make sure the following code on page load.

protected void Page_Load(object sender, EventArgs e)
{
if(!Request.UserAgent.ToLower().Contains("konqueror"))
{
if(Request.Headers["Accept-encoding"] != null
&& Request.Headers["Accept-encoding"].Contains("gzip"))
{
Response.Filter = new GZipStream(Response.Filter,
CompressionMode.Compress, true);
Response.AppendHeader("Content-encoding", "gzip");
}
else if(Request.Headers["Accept-encoding"] != null &&
Request.Headers["Accept-encoding"].Contains("deflate"))
{
Response.Filter = new DeflateStream(Response.Filter,
CompressionMode.Compress, true);
Response.AppendHeader("Content-encoding", "deflate");
}
}
}


Source : http://www.codeproject.com/aspnet/HttpCompressionQnD.asp

No comments: