我无法获取要缓存的图像文件。我已经尝试了我在这个网站和其他网站上找到的所有东西,但仍然无法将它们缓存。
我尝试过的Web配置设置
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
<httpProtocol allowKeepAlive="true" />
<caching enabled="true" enableKernelCache="true">
<profiles>
<add extension=".png" policy="CacheUntilChange" />
<add extension=".jpg" policy="CacheForTimePeriod" duration="12:00:00" />
</profiles>
</caching>
下面是其中一张图片的响应头
Key Value
Response HTTP/1.1 200 OK
Cache-Control no-cache
Content-Type image/png
Last-Modified Thu, 16 Dec 2004 18:33:28 GMT
Accept-Ranges bytes
ETag "a1ca4bc9de3c41:0"
Server Microsoft-IIS/7.5
X-Powered-By ASP.NET
Date Fri, 18 May 2012 13:21:21 GMT
Content-Length 775
发布于 2012-05-21 22:49:49
以下内容会导致浏览器缓存您的图像:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="public" />
</customHeaders>
</httpProtocol>
<caching>...</caching>
块用于服务器端缓存,而不是客户端缓存。
发布于 2018-05-30 05:54:26
如果有人需要将你的网站配置为Chrome Audit或GTMetrix,我已经用以下配置了我的环境(感谢Marco的answer):
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
使用365
days,两个工具都将该值作为缓存时间的可接受值。
https://stackoverflow.com/questions/10653549
复制相似问题