如何在IIS中为静态资源的HTTP标头中设置到期date或最大使用期限

我使用IIS 6IIS 7作为Web服务器。

网上运行Google网页速度之后,它会说我应该是这样的: Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.

它列出了很多简单的图像 ,我的JavaScript文件样式表

我如何设置这些静态文件的失效date ? 我以为这是由浏览器自动完成的?

利用浏览器caching:

在静态资源的HTTP头文件中设置失效date或最大使用期限指示浏览器从本地磁盘加载之前下载的资源,而不是通过networking。

http://code.google.com/speed/page-speed/docs/caching.html#LeverageBrowserCaching

在静态资源的HTTP标题中设置到期date或最大年龄

打开IISpipe理器 – >点击你的网站 – >点击主页中的HTTP响应头 – >点击动作面板上的设置常用标题 – >检查过期网页内容 – >设置7天后(build议在页面速度分析“为以下资源指定至less一周的到期date”

http://technet.microsoft.com/en-us/library/cc770661%28WS.10%29.aspx

有时候,如果你没有设置Cache-Control max-age和Expires头,Google工具会抱怨,IIS只是设置最大年龄,这应该是很好的。 您可以使用chrome或firebug进行确认,然后查看Net Debug面板并检查响应头。

设置静态文件的到期date应该在IIS的Web.config文件中完成。 我没有太多的ISS知识,但在网上find了这个

http://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig

 <caching> <profiles> <add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" /> <add extension=".html" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="14:00:00:00" /> </profiles> </caching> 

上面的代码将为.html文件启用最多14天的caching。 对于.php文件,请确保不执行caching。

有关更多信息,请参阅http://www.iis.net/configreference/system.webserver/staticcontent/clientcache