I had a weird problem about GZip and I hope you can help me.
using (MemoryStream memoryStream = new MemoryStream(10240))
{
//isCompressed will be true if the browser accepts gzip
using (Stream writer = isCompressed ?
(Stream)(new GZipStream(memoryStream, CompressionMode.Compress)) :
memoryStream)
{
StringBuilder sb = new StringBuilder();
//filenames is collection of multi js files need to be minify
foreach (string fileName in fileNames)
{
sb.Append(File.ReadAllText(context.Server.MapPath(fileName)));
}
//minifier is an instance of Microsoft.Ajax.Utilities.Minifier
string minifiedString = minifier.MinifyJavaScript(sb.ToString());
byte[] bts = Encoding.UTF8.GetBytes(minifiedString);
writer.Write(bts, 0, bts.Length);
}
}
The length of bts is actually over 6000, however, when writer.Write(bts, 0, bts.length) has been executed, writer can only write 2334 characters, I checked the inside info, it says, operation is not support, I was so confused, and I don’t know why?
If I understand the scenario, Vinay is correct that the 6k is being compressed. However, why use custom code to gzip your content? Why not just turn on static and dynamic compression in IIS and let IIS do the work? Furthermore, use a library like http://RequestReduce.com that will automatically combine and minify your css and js on the fly with no code and possibly no config as well as sprite your images.