I have just created Javascript & CSS handler for optimization file size using both YUI Compressor & GZip or Deflate compressor depend on request header. The following code is used to compressing file by GZipStream class. But I found that it can reduce JQuery 1.3.2(YUI compressed) file size from 58KB -> 54KB only.
public void GZipCompressFile(string filePath, string compressedFilePath)
{
FileStream sourceFile = File.OpenRead(filePath);
FileStream destFile = File.Create(compressedFilePath);
using (GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress))
{
int theByte = sourceFile.ReadByte();
while (theByte != -1)
{
theByte = sourceFile.ReadByte();
}
}
sourceFile.Dispose();
destFile.Dispose();
}
In the other hand, I compress file with 7-Zip by using gz format(Ultra compression mode). Size of compressed file is only 19.3 KB. However, I can't use 7-Zip as default compressor. Because It can't compress file by using Deflate compressor method.
Do you have any component to compress file both GZip & Deflate file type? or Do you have any idea for edit my GZipCompressFile method? Moreover, Do all new browsers(IE8,FF3.5,Opera 9.6, Safari 4) support compression method(both GZip and Deflate)?