问题描述
我一直在使用Yahoo的YSLOW来尝试使我的页面运行在 AgentX
I've been using Yahoo's YSLOW to try and make my pages go faster at AgentX
我正在使用以下压缩过滤器.当我通过Visual Studio运行该网站时,YSLOW说所有文件都被压缩,当我查看实时网站时我得到一个A,它得到一个E,并说我的文件需要压缩.谁能解释?
I am using the below compress filter. When I run the site through visual studio YSLOW says that all the files are compressed and I get an A when I view the live site it gets an E and says my files need to be gzipped. Can anyone explain?
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);
}
}
}
推荐答案
我在网站上使用了相同的机制:
I use the same mechanism on my site:
我建议使用提琴手来查看您从实时站点获得的响应是否已被压缩,然后可以确定YSlow或代码是否有问题.
I suggest using fiddler to see if your response from the live site is actually compressed and then you can determine if there is something up with YSlow or with your code.
我建议您也同时运行Google Pagespeed http://code.google.com/speed /page-speed/.这项工作与YSlow相同,但由Google完成.用于某些事物的不同算法.
I suggest that you run google pagespeed also http://code.google.com/speed/page-speed/. This does the same job as YSlow but made by google. Different algorithms for some things.
DaTribe
这篇关于压缩过滤器+ MVC +雅虎YSlow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!