dhrm
dhrm

Reputation: 14934

ASP.NET and YSlow optimization

I'm running a YSlow performance test on my small ASP.NET web project running in an IIS Express. I'm left back with two items that I think needs optimization.

1. Add Expires headers

I need to set expire date on my favicon.ico. How can I do this?

enter image description here

2. Primed cache

When I look in the statistics tab, I notice that my HTML is not cached. How can I cache the HTML, so the 6,7K is not downloaded the second time? Why is my favicon requsted in primed cache?

enter image description here

Upvotes: 0

Views: 723

Answers (1)

lstern
lstern

Reputation: 1629

favicon:

Add this to your web.config file:

<configuration>
  <location path="favicon.ico">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

Html Cache:

The browser caches a page based on the response headers of the server response. You should only ask a browser to cache a page if the page contents will not change for a given period of time and an user will revisit this page in the given period.

You an set an cache header using something like:

Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));

I recommend that you take a look at the W3C http cache specifications for a full overview about browser cache.

Also, if you use cache, some browsers will ask your server if the file was modified since the last time they get them (the "If-Modified-Since" header). If the file was not changed, you can respond with the 304 status code.

Upvotes: 1

Related Questions