IIS 7.5 and images not being cached

余生颓废 提交于 2019-12-18 10:41:40

问题


I cannot get the image files to cache. I have tried everything that I have found on this site and others and still cannot get them to cache.

Web config setting that I have tried

    <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>  

Here is the response headers for 1 of the images

    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

回答1:


The following should cause the browsers to cache your images:

<staticContent>
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
<httpProtocol>
    <customHeaders>
        <add name="Cache-Control" value="public" />
    </customHeaders>
</httpProtocol>

The <caching>...</caching> block is for server-side caching, not client side caching.




回答2:


In case anyone needs to configure your site as Chrome Audits or GTMetrix require I've configured my environments with the following (thanks to Marco's answer):

<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />

using 365 days and both tools took that value as acceptable for a cache time.



来源:https://stackoverflow.com/questions/10653549/iis-7-5-and-images-not-being-cached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!