2009-06-03 46 views
5

我一直在使用雅虎的YSlow的,試圖讓我的網頁更快的AgentX壓縮過濾器+

我使用下面的壓縮過濾MVC +雅虎YSlow的。當我通過視覺工作室運行網站時,YSLOW說所有的文件都被壓縮,當我查看實時網站時,我得到一個A,它得到一個E,並說我的文件需要被壓縮。誰能解釋一下?

public class CompressFilter : ActionFilterAttribute 
{ 
    public override void OnActionExecuting(ActionExecutingContext filterContext) 
    { 
     HttpRequestBase request = filterContext.HttpContext.Request; 

     string acceptEncoding = request.Headers["Accept-Encoding"]; 

     if (string.IsNullOrEmpty(acceptEncoding)) return; 

     acceptEncoding = acceptEncoding.ToUpperInvariant(); 

     HttpResponseBase response = filterContext.HttpContext.Response; 

     if (acceptEncoding.Contains("GZIP")) 
     { 
      response.AppendHeader("Content-encoding", "gzip"); 
      response.Filter = new GZipStream(response.Filter, 
       CompressionMode.Compress); 
     } 
     else if (acceptEncoding.Contains("DEFLATE")) 
     { 
      response.AppendHeader("Content-encoding", "deflate"); 
      response.Filter = new DeflateStream(response.Filter, 
       CompressionMode.Compress); 
     } 
    } 
} 
+0

您可以使用Firebug或Fiddler並將請求和響應數據發佈到您的實時網頁嗎? – 2009-06-03 02:55:18

回答

2

我用同樣的機制在我的網站:

http://www.avantprime.com/articles/view-article/7/compress-httpresponse-for-your-controller-actions-using-attributes

我建議使用招,看是否從活動現場的反應實際上是壓縮,然後就可以判斷,如果有什麼了YSlow或與您的代碼。

我建議你運行谷歌pagespeed也http://code.google.com/speed/page-speed/。這和YSlow做的是一樣的工作,但是是由google做的。針對某些事物的不同算法。

DaTribe

相關問題