Web Page Requests Compression
While making a request to the server, if request contains following, server can send the compressed file which will be automatically decompressed by the browser after receiving.
Accept-Encoding: gzip, deflate
Above parameters shows that browser can accept GZIP or DEFLATE compression type.
It can be easily setup from the IIS directly. Open IISManager, and click on Compression. Set the values here. Don't compress to small files and cost of compressing/ decompressing could be more than actually downloading the file.
File Requests Compression
If web site allows the user to download large files like manuals, videos etc, compression can be done on the fly. Check the following code to zip the files on the fly
using (FileStream oFileStream = article.LocalFile.OpenRead())
{
using (FileStream cFileStream = File.Create(
Guid.NewGuid().ToString() + ".gz"))
{
using (GZipStream compressionStream =
new GZipStream(cFileStream, CompressionMode.Compress))
{
oFileStream.CopyTo(compressionStream);
StreamReader reader = new StreamReader(compressionStream);
results = reader.ReadToEnd();
}
}
}
While making a request to the server, if request contains following, server can send the compressed file which will be automatically decompressed by the browser after receiving.
Accept-Encoding: gzip, deflate
Above parameters shows that browser can accept GZIP or DEFLATE compression type.
It can be easily setup from the IIS directly. Open IISManager, and click on Compression. Set the values here. Don't compress to small files and cost of compressing/ decompressing could be more than actually downloading the file.
File Requests Compression
If web site allows the user to download large files like manuals, videos etc, compression can be done on the fly. Check the following code to zip the files on the fly
using (FileStream oFileStream = article.LocalFile.OpenRead())
{
using (FileStream cFileStream = File.Create(
Guid.NewGuid().ToString() + ".gz"))
{
using (GZipStream compressionStream =
new GZipStream(cFileStream, CompressionMode.Compress))
{
oFileStream.CopyTo(compressionStream);
StreamReader reader = new StreamReader(compressionStream);
results = reader.ReadToEnd();
}
}
}
No comments:
Post a Comment