我收到了YSlow的报告:
(no expires) http://static3.scirra.net/avatars/128/40cfdcbd1b1ec1842e199c97c4b85a4a.png
(和更多相似)。但是在我的web.config中,我有:
<system.webServer>
<staticContent>
<clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
</staticContent>
<caching>
<profiles>
<add extension=".ashx" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="01:00:00" />
<add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" location="Any" />
</profiles>
</caching>
<rewrite>
<rules>
<rule name="Avatar">
<match url="avatars/([0-9]+)/(.*).png" />
<action type="Rewrite" url="gravatar.ashx?hash={R:2}&size={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
这不应该正确添加expires标头吗?我的目标是:
答案 0 :(得分:1)
在IIS中,您可以定义HTTP标头。
在IIS中单击您的images文件夹。然后单击HTTP响应标头。然后设置公共标题...
从这里,您可以查看过期网页内容以及您选择的时间。您也可以为JS和CSS执行此操作。请注意您也应用哪些文件。此外,如果您设置了非常远的过期并且您计划更改这些文件,则可能会导致您的网站出现问题。
如果您在JS文件上有1个月到期,然后在使用相同名称时进行更改,那么当用户访问您的站点时,他们将看到内容未过期,并且不会从Web服务器请求更改的文件。您可以通过设置适度的到期时间来应对此问题,同时您认为内容可能会发生变化,或者您可以将版本号应用于您的javascript和CSS文件。