1. 程式人生 > >轉載 IIS設置瀏覽器緩存模式

轉載 IIS設置瀏覽器緩存模式

img ora out AR 分享 mod net chan 瀏覽器緩存

IIS中User-mode caching引起的Cache-Control不為public問題的解決方法

轉載 更新時間:2013年11月22日 16:06:34 作者: 技術分享圖片 我要評論

在IIS的Output caching中如果啟用了User-mode caching將引起Cache-Control為no-cache,從而造成頁面不能被瀏覽器或代理服務器緩存,下面看解決方法

技術分享圖片


web.config中對應的配置如下:

復制代碼代碼如下:
<configuration>
<system.webServer>
<caching>
<profiles>
<add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="00:00:30" />
<add extension=".js" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="00:00:30" />
</profiles>
</caching>
</system.webServer>
</configuration>

瀏覽器中看到的效果:

技術分享圖片

解決方法:

1、禁用User-mode caching,只用Kernel-mode caching。

技術分享圖片

2、在web.config中加上cacheControlCustom="public"

復制代碼代碼如下:
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="300.00:00:00" />
</staticContent>
<caching>
<profiles>
<add extension=".css" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="30:00:30" />
<add extension=".js" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="30:00:30" />
</profiles>
</caching>
</system.webServer>
</configuration>

轉載 IIS設置瀏覽器緩存模式