HTTP的COM pression:一些外部脚本/ CSS不DECOM pressing一些正确的时间 [英] HTTP Compression: Some external scripts/CSS not decompressing properly some of the time

查看:137
本文介绍了HTTP的COM pression:一些外部脚本/ CSS不DECOM pressing一些正确的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行页/ COM资源pression以提高网站的性能。

我试图同时实现blowery和邪恶HttpCom preSS但最终得到了相同的结果。这只似乎影响Firefox的,我已经在Chrome和IE测试。

会发生什么事是我第一次请求页面的所有外部资源DECOM preSS确定。第2或第3次的页面有错误,因为资源似乎并没有被DECOM pressed。我得到UNI code字符,如:


 í½`I%安培; / ME {JõJ×àt¡`$ @Ø#ìÁÍæìiG)«*ÊeVeF的


(实际上它们不能被正确显示在这里)

通过萤火检查页面将显示响应头为:


  

缓存控制私人


  
  

内容类型text / html;字符集= UTF-8


  
  

内容编码gzip的


  
  

服务器Microsoft-IIS / 7.5


  
  

X-AspNetMvc-2.0版


  
  

X-ASPNET-版本2.0.50727


  
  

幽浮pressed,通过HttpCom preSS


  
  

X-已启动由ASP.NET日期星期五,09七月


  
  

2010 GMT六时51分40秒的Content-Length 2622


这明确指出,资源是COM pressed由gzip的。所以,有些事情似乎要在客户端上的放气侧错了?

我在web.config中添加了以下部分(在适当的位置):

 < sectionGroup NAME =blowery.web>
  <节名称=htt​​pCom preSSTYPE =blowery.Web.HttpCom press.SectionHandler,blowery.Web.HttpCom preSS/>
< / sectionGroup>< blowery.web>
    < httpCom preSS preferredAlgorithm =gzip的COM pressionLevel =高>
      < excludedMimeTypes>
        <添加类型=图像/ JPEG/>
        <添加类型=图像/ PNG/>
        <添加类型=图像/ GIF/>
      < / excludedMimeTypes>
      < excludedPaths>
        <添加路径=NoCom press.aspx/>
      < / excludedPaths>
    < / httpCom preSS>
< /blowery.web><添加名称=的COM pressionModuleTYPE =blowery.Web.HttpCom press.HttpModule,blowery.web.HttpCom preSS/>

任何帮助吗?


解决方案

这是我有看到之前的问题,问题是,内容长度是不正确的。为什么不正确?因为它的COM pression之前大概计算了。

如果您通过手工设置内容Lenght,只是将其删除,并让模块设置,如果他能。

我注意到,您使用 Blowery COM pression 。也许这里面Blowery一个bug /问题。如果你不能找到它,解决它,为什么不使用MS COM pression?

@ptutt 如果你是共享IIS,那么也许有都准备一套COM pression,所以有一个COM pression比其他的,你只需要删除你的。如果是这样的问题,那么可以肯定的内容lenght是假的,因为第一个COM pression之后,第二个是打破它。

检查出来使用本网站 http://www.pipeboost.com /report.asp 如果您的网页都准备好了COM $ p $由IIS默认pssed。

如果没有COM pressed默认情况下,那么你可以做到这一点很容易。在Global.asax中

 保护无效的Application_BeginRequest(对象发件人,EventArgs的发送)
{
    字符串cTheFile = HttpContext.Current.Request.Path;
    字符串sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);    如果(sExtentionOfThisFile.Equals(ASPX,StringComparison.InvariantCultureIgnoreCase))
    {
        字符串acceptEncoding = MyCurrentContent.Request.Headers [的Accept-Encoding]。ToLower将();;        如果(acceptEncoding.Contains(放气)|| acceptEncoding ==*)
        {
            // defalte
            HttpContext.Current.Response.Filter =新DeflateStream(prevUncom pressedStream,
                COM pressionMode.Com preSS);
            HttpContext.Current.Response.AppendHeader(内容编码,放气);
        }否则如果(acceptEncoding.Contains(gzip的))
        {
            // gzip的
            HttpContext.Current.Response.Filter =新GZipStream(prevUncom pressedStream,
                COM pressionMode.Com preSS);
            HttpContext.Current.Response.AppendHeader(内容编码,gzip的);
        }
    }
}

请注意,我只是写这篇code和没有测试。我的code更有点复杂,所以我只是创建它的一个简单的优化版本。

查找更多的例子:
http://www.google.com/search?q=Response.Filter+GZipStream

参考:
<一href=\"http://stackoverflow.com/questions/2582139/2719080#2719080\">http://stackoverflow.com/questions/2582139/2719080#2719080

I am implementing page/resource compression to improve website performance.

I have tried to implement both blowery and wicked HttpCompress but end up getting the same result. This only seems to affect Firefox, I have tested on Chrome and IE.

What happens is the first time I request the page all the external resources decompress ok. The 2nd or 3rd time the page has errors because the resource doesn't seem to be decompressed. I get unicode characters like:

������í½`I%&/mÊ{JõJ×àt¡`$Ø@ìÁÍæìiG#)«*ÊeVe]f

(actually they can't be displayed properly here)

Inspecting the page via firebug displays the response header as:

Cache-Control private

Content-Type text/html; charset=utf-8

Content-Encoding gzip

Server Microsoft-IIS/7.5

X-AspNetMvc-Version 2.0

X-AspNet-Version 2.0.50727

X-Compressed-By HttpCompress

X-Powered-By ASP.NET Date Fri, 09 Jul

2010 06:51:40 GMT Content-Length 2622

This clearly states that the resource is compressed by gzip. So something seems to be going wrong on the deflate side on the client?

I have added the following sections (in the appropriate locations) in the web.config:

<sectionGroup name="blowery.web">
  <section name="httpCompress" type="blowery.Web.HttpCompress.SectionHandler, blowery.Web.HttpCompress"/>
</sectionGroup>

<blowery.web>
    <httpCompress preferredAlgorithm="gzip" compressionLevel="high">
      <excludedMimeTypes>
        <add type="image/jpeg"/>
        <add type="image/png"/>
        <add type="image/gif"/>
      </excludedMimeTypes>
      <excludedPaths>
        <add path="NoCompress.aspx"/>
      </excludedPaths>
    </httpCompress>
</blowery.web>

<add name="CompressionModule" type="blowery.Web.HttpCompress.HttpModule, blowery.web.HttpCompress"/>

Any help?

解决方案

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: http://stackoverflow.com/questions/2582139/2719080#2719080

这篇关于HTTP的COM pression:一些外部脚本/ CSS不DECOM pressing一些正确的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆