Cache-Control Header & Browser Caching IIS7

妖精的绣舞 提交于 2019-12-04 08:42:32

问题


I am using Google Page Speed on my website in IIS7 and I was wondering how to set

Leverage browser caching - The following resources are missing a cache expiration
Leverage proxy caching - Consider adding a "Cache-Control: public" header to the following resources.

I am using doDynamicCompression in my web.config and little confused how to set these ? Hoping for some help

Note: Reference being used http://www.iis.net/ConfigReference/system.webServer/httpCompression


回答1:


Under system.webServer in web.config set for example

<caching>
            <profiles>
                <add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" location="Any" />
                <add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" location="Any" />
                <add extension=".gif" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" location="Any" />
            </profiles>
        </caching>

This can also be configured from IIS Manager under Output Caching but what the GUI doesn't do is set the 'location' attribute. Setting it to 'Any' will set Cache-Control:public.

You can read more about it here.




回答2:


I imagine you already figured this out, but read up on setting content expiration in IIS here.

Note that this only applies to static content served by IIS. If you are looking to set caching headers for dynamic content (ASPX, PHP, ISAPI, whatever), you need to generate your own Expires and Cache-Control headers in your application. IIS will (quite correctly) not attempt to apply cache-control headers to dynamic pages that may include Set-Cookie headers or private data. ASP and ASP.net automatically set "Cache-Control: private" by default for all pages, but you can override that behavior on a per-response basis.



来源:https://stackoverflow.com/questions/1368113/cache-control-header-browser-caching-iis7

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