0

我正在对在 IIS Express 中运行的小型 ASP.NET Web 项目运行 YSlow 性能测试。我留下了两个我认为需要优化的项目。

1.添加过期标题

我需要在我的 favicon.ico 上设置过期日期。我怎样才能做到这一点?

在此处输入图像描述

2. 缓存

当我查看统计选项卡时,我注意到我的 HTML 没有被缓存。我怎样才能缓存 HTML,这样 6,7K 就不会第二次下载了?为什么我的 favicon 需要在已准备好的缓存中?

在此处输入图像描述

4

1 回答 1

1

favicon:

Add this to your web.config file:

<configuration>
  <location path="favicon.ico">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

Html Cache:

The browser caches a page based on the response headers of the server response. You should only ask a browser to cache a page if the page contents will not change for a given period of time and an user will revisit this page in the given period.

You an set an cache header using something like:

Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));

I recommend that you take a look at the W3C http cache specifications for a full overview about browser cache.

Also, if you use cache, some browsers will ask your server if the file was modified since the last time they get them (the "If-Modified-Since" header). If the file was not changed, you can respond with the 304 status code.

于 2013-05-20T03:36:43.423 回答