简体   繁体   中英

How do you set the expiry date or a maximum age in the HTTP headers for static resources in IIS

I am using IIS 6 and IIS 7 as a web server.

After running Google page speed online , it remarks that I should be: 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.

And it lists a lot of plain images , my javascript files and the style sheets .

How can I set this expiry date for these static files ? I thought this was done automatically by the browser ?

Leverage browser caching:

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.

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

To set an expiry date or a maximum age in the HTTP headers for static resources

Open IIS manager-> Click your site-> Click the HTTP Response Headers in the home page-> Click the Set Common Headers on the Actions panel -> Check Expire Web Content -> Set After 7 days (as suggested for in the page speed analysis "Specify an expiration at least one week in the future for the following resources"

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

Sometimes the google tool complains if you don't set both the Cache-Control max-age and the Expires header, IIS just sets the max-age, which should be fine really. You can confirm by using chrome or firebug and looking at the Net Debug panel and inspecting the response headers.

setting expiry date for static files should be done in Web.config file for IIS. I don't have much knowledge in ISS, but found this on web

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>

The above code will enable caching for .html files for a maximum of 14 days. For .php files, ensure that no caching is performed.

For more refer http://www.iis.net/configreference/system.webserver/staticcontent/clientcache

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM