Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asking browsers to cache our images (ASP.NET/IIS)

I just ran Google's Page Speed application against our site and one of the recommendations was to Leverage browser caching. Expanding this revealed the following:

The following cacheable resources have a short freshness lifetime: Specify an expiration at least one week in the future for the following resources:

<a long list of images >
<some javascript files >

How do I go about lengthening the "freshness lifetime" of particular images?

It's an ASP.NET project running on IIS7.5

like image 935
Chuck Le Butt Avatar asked Jun 10 '10 18:06

Chuck Le Butt


1 Answers

I found the answer to my question elsewhere on this site. Woot! (Not sure why it didn't appear when I first posted this, but never mind, I got there in the end.)

For those interested, the answer was this (as posted by Gabriel McAdams):


You do that in IIS. If you are using IIS 7, you can add the header in your web.config. It’s in the system.webServer section.

<staticContent>
    <clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
</staticContent>

This will cause all static content to have an expires HTTP header set to the year 2020. Static content means anything that isn’t served through the ASP.NET engine such as images, script files and styles sheets.

Or to use a relative expiration, use this:

<staticContent>
    <clientCache cacheControlMaxAge ="2.00:00:00" cacheControlMode="UseMaxAge" />
</staticContent>

This will cause all static content to have an expires HTTP header set to 2 days.

like image 107
Chuck Le Butt Avatar answered Oct 02 '22 20:10

Chuck Le Butt