4

I want to cache all my static content of mvc application.

I Added Web.config file like this in the Content folder enter image description here

I got proper response header from my server.

enter image description here

Even after receiving the header with max-age attribute, The next Request to the server goes with Cache-Control: no-cache

enter image description here

This again retrieve the whole data.

It is not caching.

I want to know What am i missing here. Thanks in advance.

4
  • What is the static content being served? HTML? Image? Something else? Commented Jun 7, 2017 at 12:31
  • I am trying to cache css file Commented Jun 7, 2017 at 12:44
  • Is it a public css file that you are willing to share the link to, so we can test it? Commented Jun 7, 2017 at 12:45
  • Yes It is a public css file. Commented Jun 7, 2017 at 12:49

1 Answer 1

3

The no-cache in your screenshot is a request header not a response header.

It is likely being issued by your browser in response to you forcing a refresh (Control-F5). The browser is effectively saying 'please get me fresh data, I don't want the cached data'. The server-side can't control this - the client is the one making the request.

If you aren't forcing a refresh then you may have disabled your browser cache (e.g. https://stackoverflow.com/a/7000899/34092 ).

See also https://stackoverflow.com/a/14544664/34092 .

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

5 Comments

Yes no-cache in my screenshot is a request header. But My Browser asks for the data even after the server set its response header(max-age=3600).
The browser is allowed to do that. You ultimately can't stop it doing that. Think of cache headers as 'hints' for the browser - it doesn't have to pay attention to them. Have you perhaps disabled the cache on your browser (e.g. stackoverflow.com/a/7000899/34092)?
Then what might be reason for the browser asks for the data even after set its response header to max-age=3600
The main two reasons are the ones I have mentioned. You force refreshed the page (Control-F5) or you disabled the cache in your browser.
Thanks a lot. My Browser disabled cache when developer tool is Opened.

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.