Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify HTTP expiration header? (ASP.NET MVC+IIS)

I am already using output caching in my ASP.NET MVC application.

Page speed tells me to specify HTTP cache expiration for css and images in the response header.

I know that the Response object contains some properties that control cache expiration. I know that these properties can be used to control HTTP caching for response that I am serving from my code:

Response.Expires Response.ExpiresAbsolute Response.CacheControl 

or alternatively

Response.AddHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT"); 

The question is how do I set the Expires header for resources that are served automatically, e.g. images, css and such?

like image 996
Marek Avatar asked Apr 09 '10 15:04

Marek


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.

What is expired HTTP 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.

What will happen if you set an Expires header to a later date say 1 day )?

When you set an expires header for a resource, such as all jpeg images, the browser will store those resources in its cache. The next time the visitor comes back to the page it will load faster, as the browser will already have those images available.


1 Answers

Found it:

I need to specify client cache for static content (in web.config).

<configuration>   <system.webServer>     <staticContent>       <clientCache cacheControlCustom="public"        cacheControlMaxAge="12:00:00" cacheControlMode="UseMaxAge" />     </staticContent>    </system.webServer> </configuration> 

from http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache

like image 120
Marek Avatar answered Sep 20 '22 11:09

Marek