.net – Add Expires or Cache Control Header to static content in IIS

cachinghttpiisnet

After running the YSlow plugin on a site, I saw that one of the recommendations was to add far future expires headers to the scripts, stylesheets, and images.

I would like to do this, does anyone have experience with this? I am using IIS 7 and I read an article from Microsoft but am not interested in disabling caching for asp pages or images, I actually want to force caching for static content. Also, the ideal situation would not exist in code, but in the web server configuration.

So, what steps would I have to take to have every image, javascript file, and stylesheet to be cached?

Best Answer

Can this be done in IIS 6?

To configure content expiration

  1. In the Internet Information Services (IIS) Manager administrative tool, right-click Your Web Site, and then click Properties.

  2. In the Properties dialog box, on the HTTP Headers tab specify expiration time, and then click OK.