YSLOW Expiry Headers on MVC 5 Web Site

2.6k Views Asked by At

I used YSlow to test an ASP.NET MVC web site and I got the error:

"Add Expiry Headers" for the following items:

(no expires) http://www.mydomain.pt/assets/logo.png  
(no expires) http://www.mydomain.pt/favicon-196x196.png  
(2013/12/30) http://www.mydomain.pt/file/e6fb9d2a-668b-423a-9120-0b34228f296c  

What is strange is that I addressed these issues. For static I used:

CORRECTED

<system.webServer>  
  <clientCache setEtag="false" cacheControlMode="UseMaxAge" cacheControlMaxAge="60.00:00:00" />
</system.webServer>

And for the file, returned by an action, I have:

[Route("file/{identifier:guid}"), HttpGet, OutputCache(Duration = 1200, Location = OutputCacheLocation.Client, VaryByParam = "identifier")]
public virtual ActionResult Get(Guid identifier, String n = null) {
}

Does anyone knows why I still have no cache on these items?

Am I missing something?

Thank You, Miguel

2

There are 2 best solutions below

2
On

Compressing static files doesn't have anything to do with expiration headers. Compression is related to GZip.

The reason the .png files do not have the Expiry header that you are setting in the action method, is that MVC is not being used to serve the static files, so it will not set the headers.

Add expires header to images

0
On

Use following syntax:

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