48

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?

Brian Grinstead
  • 3,480
  • 5
  • 29
  • 23
  • for ASP.NET Core, see [Change the headers of static files in Asp.net Core](https://stackoverflow.com/questions/29256244/change-the-headers-of-static-files-in-asp-net-core) – S.Serpooshan Oct 21 '18 at 08:11

2 Answers2

8

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.

Vladislav
  • 1,696
  • 27
  • 37
  • 8
    Does this affect only static content such as images / style sheets? I don't want IIS to tell the browser to cache aspx pages that get updated frequently. – Code Commander Mar 01 '11 at 17:27
6

I added a custom header on the http headers tab instead of checking the box, because I could not include "public" in the Cache Control header otherwise.

I did this for folders with static content such as /images/, /scripts/, /css/ and a few others, not the whole project.

Name: Cache-Control Value: public, max-age=604800

VR

v1rich
  • 61
  • 1
  • 1