评论

收藏

[IIS] IIS中User-mode caching引起的Cache-Control不为public问题的解决方法

web服务器 web服务器 发布于:2021-10-02 11:23 | 阅读数:211 | 评论:0

DSC0000.jpg


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>
浏览器中看到的效果:

DSC0001.jpg
解决方法:
1、禁用User-mode caching,只用Kernel-mode caching。

DSC0002.jpg
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>
关注下面的标签,发现更多相似文章