2

I want to cache static content of my asp.net mvc 3 app. I added this tag in web.config to cache for 10 days:

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

but it seens doesn't work (checked using YSlow and Fiddler). Any ideas why?

4
  • I tried on DevServer, IIS Express and IIS 7.5 Commented Dec 4, 2011 at 15:41
  • Does the server send the Cache-Control header at all ? Commented Dec 4, 2011 at 15:50
  • Yes. Cache-Control:max-age=36000 Commented Dec 4, 2011 at 15:58
  • Well, then it works. See my answer below. Commented Dec 4, 2011 at 16:29

1 Answer 1

3

Based on the comments we've exchanged above, I'd say that the client side caching works.

Your server sends:

 Cache-Control:max-age=36000

Which means, that the client should cache it for 10 hours (60 * 60 * 10 == 36000). If you actually want 10 days, the configuration is:

cacheControlMaxAge="10.00:00:00" 

Remember that the client might decide to retrieve the resource again regardless of your cache headers, for any number of reasons (such as the client side cache has been purged, the user requested a full refresh, the client doesn't implement client side caching properly, etc. etc.)

How did you arrive at the conclusion that it doesn't work ?

Sign up to request clarification or add additional context in comments.

2 Comments

I checked it using YSlow Fiddler and Chrome dev tool. Every time I refresh page it always makes request to static content (http status 200).
The server tells the client the right thing, but refreshing in this case also means to refresh the cached resources. If you just nnavigate to the page, the browser should use the cached version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.