【问题标题】:Set caching on CSS files on IIS7 is not working在 IIS 7 上设置 CSS 文件缓存不起作用
【发布时间】:2015-02-20 10:17:10
【问题描述】:

我正在尝试实施 Google 的 Pagespeed 关于浏览器缓存的建议(在静态内容上设置 Expirer 或 Cache-control 标头)。 在这里阅读了很多帖子(如 IIS7 Cache-Control )和其他网站后,我似乎无法弄清楚为什么 Pagespeed 仍然不批准我的 CSS 文件。

例如:http://test.grotefeesten.nl/clientdata/71/js/jssor.config.js。此文件根据本地 PageSpeed 的过期时间为 1 天,但根据在线 PageSpeed 测试没有。

我的 web.config:

 <caching>
  <profiles>
    <add extension=".css" policy="CacheUntilChange" 
     kernelCachePolicy="CacheUntilChange" location="Any" />
  </profiles>
 </caching>
 <httpProtocol>
 <customHeaders>
   <add name="Cache-Control" value="public" />
 </customHeaders>
 </httpProtocol>
 <staticContent>
   <clientCache cacheControlMode="UseMaxAge" cacheControlCustom="max-age"
    cacheControlMaxAge="1.00:00:00" />
 </staticContent>

有人看到我在这里缺少什么来正确设置 Expires 标头吗?

【问题讨论】:

    标签: iis-7 cache-control


    【解决方案1】:

    我自己也一直在为此苦苦挣扎。不过,我找到了解决方案:

    <httpProtocol>
        <customHeaders>
            <add name="Cache-Control" value="max-age=2592000" />
        </customHeaders>
    </httpProtocol>
    

    这就是全部。上面代码"max-age=2592000"中的值是1个月。

    【讨论】:

      猜你喜欢
      • 2021-10-18
      • 2018-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 2011-04-25
      • 1970-01-01
      • 2012-12-23
      相关资源
      最近更新 更多