我一直在使用雅虎的 YSLOW 来尝试让我的页面在AgentX上运行得更快
我正在使用下面的压缩过滤器。当我通过 Visual Studio 运行该站点时,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);
}
}
}