使用IIS8.5进行浏览器缓存,我做得对吗?

时间:2015-03-16 07:41:10

标签: asp.net caching iis

我已将以下规则应用于我的web.config;

 <staticContent>
    <mimeMap fileExtension=".less" mimeType="text/less" />
    <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00" />
</staticContent>
<httpProtocol>
   <customHeaders>
      <remove name="Vary"></remove>
      <add name="Vary" value="Accept-Encoding" />
      <add name="Cache-Control" value="public" />
   </customHeaders>
</httpProtocol>

<caching>
   <profiles>
     <add extension=".gif" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="5.00:00:00" />
     <add extension=".png" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="5.00:00:00" />
     <add extension=".jpg" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="5.00:00:00" />
     <add extension=".ico" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="30.00:00:00" />
     <add extension=".woff2" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="5.00:00:00" />
     <add extension=".woff" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="5.00:00:00" />
     <add extension=".ttf" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="5.00:00:00" />
     <add extension=".js" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="2.00:00:00" />
     <add extension=".css" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="2.00:00:00" />
  </profiles>
</caching>

问题是,当我检查响应时,我有这个输出Cache-Control no-cache,max-age=864000。 no-cache是​​否意味着浏览器没有缓存它?

以下是输出示例

Accept-Ranges   bytes
Cache-Control   no-cache,max-age=864000,public
Content-Encoding    gzip
Content-Length  249
Content-Type    text/css
Date    Mon, 16 Mar 2015 07:37:29 GMT
Etag    "872ee528715ed01:0"
Last-Modified   Sat, 14 Mar 2015 16:08:50 GMT
Server  Microsoft-IIS/8.5
Vary    Accept-Encoding
X-Powered-By    ASP.NET

1 个答案:

答案 0 :(得分:1)

是的,您做得对,页面缓存良好。

您可以参考Cache-Control MDN的说明。 Cache-Control标头值 no-cache 表示缓存在使用缓存副本之前必须与原始服务器进行验证。 您的缓存将每隔 864000 秒重新验证一次。它可能使用带有If-Match的{​​{1}}或If-None-Match标头来重新验证内容,或者可能使用带有日期的ETagIf-Modified-Since标头。这是MDN的指令说明,

最大年龄 = If-Unmodified-Since 资源被视为新鲜的最长时间。与Expires不同,此指令是相对于请求时间的。

无缓存 缓存必须在使用缓存副本之前与原始服务器进行确认。

相关问题