Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

http expire headers in asp.net with web.config

I'm trying to get YSlow to give me an A on the "Add Expires header" section by setting the web.config file.

I've been looking around and this is what I put in based on what's out there:

<staticContent>     <clientCache httpExpires="15.00:00:00" cacheControlMode="UseExpires"/>     </staticContent> </system.webServer> 

This is what I'm seeing in Firebug:

Response Headers  HTTP/1.1 200 OK Server: ASP.NET Development Server/10.0.0.0 Date: Sun, 28 Aug 2011 13:54:50 GMT X-AspNet-Version: 4.0.30319 Cache-Control: private Content-Type: image/jpeg Content-Length: 24255 Connection: Close   Request Headersview source Host    localhost:50715 User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0 Accept  image/png,image/*;q=0.8,*/*;q=0.5 Accept-Language en-us,en;q=0.5 Accept-Encoding gzip, deflate Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7 Connection  keep-alive Referer http://localhost:50715/MySite/SiteHome.html Pragma  no-cache Cache-Control   no-cache 

However, when I look at it in Firefox, Yslow is still giving an F on this, even after a Crtl-F5

What am I missing?

Thanks.

like image 667
frenchie Avatar asked Aug 28 '11 13:08

frenchie


1 Answers

From .NET Daily, I successfully applied this to a PHP site on IIS. It sets the max age to 30 days from now, rather than having to specify an explicit date.

Add this to your web.config file:

<system.webServer>   <staticContent>     <clientCache cacheControlMaxAge="30.00:00:00" cacheControlMode="UseMaxAge"/>   </staticContent> </system.webServer> 

This configuration satisfies both PageSpeed "Leverage browser caching" and YSlow "Add Expires headers". YSlow requires a value greater than 7 days. PageSpeed requires between 30 days and 1 year.

like image 147
markd Avatar answered Sep 27 '22 23:09

markd