繁体   English   中英

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

[英]Browser Caching using IIS8.5, am I doing it right?

我已将以下规则应用于我的 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

是的,你做对了,你的页面缓存得很好。

可以参考Cache-Control MDN的解释。 Cache-Control 标头值no-cache意味着缓存必须在使用缓存副本之前与源服务器进行验证。 您的缓存将每864000秒重新验证一次。它可能会使用If-MatchIf-None-Match标头与ETag重新验证内容,或者它可能使用If-Modified-SinceIf-Unmodified-Since标头与一个约会。 这是来自 MDN 的指令解释,

max-age = <seconds>资源被视为新鲜的最长时间。 与 Expires 不同,该指令与请求的时间有关。

no-cache缓存必须在使用缓存副本之前检查源服务器以进行验证。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM