HTTP Compression: Some external scripts/CSS not decompressing properly some of the time

南楼画角 提交于 2019-11-27 15:52:12
Aristos

This is an issue that I have see before and the problem is that the Content-Length is not correct. Why is not correct ? because its probably calculate before the compression.

If you set Content-Lenght by hand, just remove it and let the module set it if he can.

I note that you use the Blowery compression. Probably this is a bug/issue inside Blowery. If you can not locate it and fix it, why not use the Ms compression ?

@ptutt if you are on shared iis, then maybe there have all ready set compression, so there is one compression over the other, and you only need to remove yours. If this is the issue then for sure the content-lenght is false because after the first compression, the second is break it.

Check it out using this site http://www.pipeboost.com/report.asp if your pages all ready compressed by default by iis.

If not compressed by default then you can do it very easy. On Global.asax

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    string cTheFile = HttpContext.Current.Request.Path;
    string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);

    if (sExtentionOfThisFile.Equals(".aspx", StringComparison.InvariantCultureIgnoreCase))
    {
        string acceptEncoding = MyCurrentContent.Request.Headers["Accept-Encoding"].ToLower();;

        if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
        {
            // defalte
            HttpContext.Current.Response.Filter = new DeflateStream(prevUncompressedStream,
                CompressionMode.Compress);
            HttpContext.Current.Response.AppendHeader("Content-Encoding", "deflate");
        } else if (acceptEncoding.Contains("gzip"))
        {
            // gzip
            HttpContext.Current.Response.Filter = new GZipStream(prevUncompressedStream,
                CompressionMode.Compress);
            HttpContext.Current.Response.AppendHeader("Content-Encoding", "gzip");
        }       
    }
}

Please note, I just write this code and have not tested. My code is a little more complicate, so I just create a simple verion of it.

Find more examples: http://www.google.com/search?q=Response.Filter+GZipStream

Reference: ASP.NET site sometimes freezing up and/or showing odd text at top of the page while loading, on load balanced servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!