Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Expires or Cache Control Header to static content in IIS

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?

like image 203
Brian Grinstead Avatar asked May 14 '09 19:05

Brian Grinstead


People also ask

How do you set cache control for static content?

Here is what you need to remember while caching static resources on CDN or local cache server: Use Cache-control HTTP directive to control who can cache the response, under which conditions, and for how long. Configure your server or application to send validation token Etag. Do not cache HTML in the browser.

How do I add expired headers in IIS?

To configure an Expires header in IIS, right-click the Default Web Site in the Computer Management Console, select Properties, then click the HTTP Headers tab, which Figure 4 shows. Select the Enable Content Expiration check box and choose your expiration preferences.

How do I add a cache control header?

To use cache-control in HTML, you use the meta tag, e.g. The value in the content field is defined as one of the four values below. HTTP 1.1. Allowed values = PUBLIC | PRIVATE | NO-CACHE | NO-STORE.


1 Answers

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.

like image 72
Vladislav Avatar answered Sep 19 '22 23:09

Vladislav