Add Expires or Cache Control Header to static cont

2019-01-10 09:23发布

问题:

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?

回答1:

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.



回答2:

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