There are 2 types of http Compressions
1). Gzip and 2). Deflate
As per my knowledge Gzip is the default one.( but please conform too)
to implement this, we just need to import these classes
1). System.IO; 2). System.IO.Compression;
To implement this functionality to your website, add a global file and under the Application_BeginRequest use this code,
HttpApplication oApp = (HttpApplication)sender; string acceptEncoding = oApp.Request.Headers["Accept-Encoding"]; Stream prevUncompressedStream = oApp.Response.Filter;
if (acceptEncoding == null || acceptEncoding.Length == 0) return;
acceptEncoding = acceptEncoding.ToLower();
if (acceptEncoding.Contains("gzip")) { // gzip oApp.Response.Filter = new GZipStream(prevUncompressedStream, CompressionMode.Compress); oApp.Response.AppendHeader("Content-Encoding", "gzip"); } else if (acceptEncoding.Contains("deflate")) { // defalte oApp.Response.Filter = new DeflateStream(prevUncompressedStream, CompressionMode.Compress); oApp.Response.AppendHeader("Content-Encoding", "deflate"); }
now the http compression will be automatically work for your asp.net pages.
you can check the sites here for http Compression, but it not work for local.
http://www.port80software.com/surveys/top1000compression/#checkyoursite
Please correct me, if i am wrong some where
have a good learning.
If we use gzip for dotnetspider.com, 68.0% traffic can be saved. to check this, go to the same URL i have given above.
|
| Author: thebarrett27 04 May 2009 | Member Level: Bronze Points : 0 |
nice article. thanks
|