Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the "Expire Web Content" common http response header in IIS

We have a fairly high-volume IIS7.0 site (about 1 million requests a day), a lot of which are Images/CSS/JS.

As a quick way to reduce this, I'm considering setting the common http response header to expire web content some fixed date way in the future, and an wondering what possible disadvantages we could get with this.

Looking at the web.config change resulting from setting this, it adds:

<staticContent>
    <clientCache cacheControlMode="UseExpires" cacheControlMaxAge="1.00:00:00" httpExpires="Thu, 01 Oct 2020 00:00:00 GMT" />
</staticContent>

My worry is that if we wanted to change one of the CSS/JS/Images after setting this, clients wouldn't pick up the changes and whilst images probably won't change, CSS/JS certainly will. Does that mean we should only set this on for folders containing only images? Or does this mean we need to introduce versioned URLs for our CSS/JS?

like image 974
Kram Avatar asked Oct 10 '11 15:10

Kram


People also ask

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 change the response header in IIS?

Add custom HTTP response header in IIS 7.0In the connections pane, expand the node for the server, and then expand Sites. Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add.

What is expired response header?

The Expires HTTP header contains the date/time after which the response is considered expired. Invalid expiration dates with value 0 represent a date in the past and mean that the resource is already expired.


1 Answers

You should always cache static content (Images, CSS, JS)

Even when cached, most browsers will still politely inquire the server as to whether a newer version is available (If-Modified-Since) and the server will reply with a Not Modified. (e.g. IE defaults to "automatically check for new versions of pages")

One caveat : if there are other proxies in between your server and clients, then these proxies may elect strictly to adhere to your cache settings, and could serve 'stale' content, so you will need to apply some thought to the optimal duration of caching.

like image 122
StuartLC Avatar answered Oct 05 '22 17:10

StuartLC