簡體   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