1

我已经通过 microhosting.in 购买了共享主机 在为我的初创公司整理网站之后,自然而然的下一步就是推广。所以我检查了性能。Pagespeed 测试指出缓存和未压缩的 http 存在问题。现在,通过 Plesk 托管 Windows 意味着对于任何 IIS 功能要求,我必须明确说服托管服务提供商,除非使用 Web.config。技术团队有点弱,无法尝试http://blog.fi.net.au/?p=372使用 http 启用公共缓存,因为代理缓存可能会抑制元标记内容嗅探,应该是可取的。是否有任何自定义实现可以与 Web.config 结合起来应用这些,就像我在任何地方找到使用 .htaccess 的解决方案一样?

4

1 回答 1

0

将可选内容压缩在单独的文件夹中,并使用其自己的 web.config 强制将内容编码相关属性添加到标头。对于强制性内容,重命名文件以使用 asp.net 运行时并放置 --> 将 ContentType 替换为预期的 MIME 类型,嵌套在某个标记中,因为在服务器端 xsl 转换期间将其放置在最外层或未注释为默认刺激。现在在 global.asax 中实现以下 C# 逻辑

 void Application_PreRequestHandlerExecute(object sender, EventArgs e)
 {
     HttpApplication app = sender as HttpApplication;
    string acceptEncoding = app.Request.Headers["Accept-Encoding"];
    Stream prevUncompressedStream = app.Response.Filter;

    if (acceptEncoding == null || acceptEncoding.Length == 0)
        return;

    acceptEncoding = acceptEncoding.ToLower();

    if (acceptEncoding.Contains("gzip"))
    {
        // gzip
        app.Response.Filter = new GZipStream(prevUncompressedStream,
            CompressionMode.Compress);
        app.Response.AppendHeader("Content-Encoding", "gzip");
    }       /*else if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
    {
        // defalte
        app.Response.Filter = new DeflateStream(prevUncompressedStream,
            CompressionMode.Compress);
        app.Response.AppendHeader("Content-Encoding", "deflate");
    }*/    // Only cache for X seconds.
Response.Cache.SetExpires(DateTime.Now.AddMonths(9));
Response.Cache.SetMaxAge(new TimeSpan(270, 0, 0,0,0));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);

// Sliding expiration means we reset the X seconds after each request.
// SetETag is required to work around one aspect of sliding expiration.
Response.Cache.SetSlidingExpiration(true);
Response.Cache.SetETagFromFileDependencies();

}
于 2012-12-13T13:53:05.590 回答