Link to home
Start Free TrialLog in
Avatar of Maarten Bruins
Maarten Bruins

asked on

Preventing caching via .htaccess file (Apache)?

To completely prevent caching (storing it and using it), usually on the internet they are saying you have to use something like this in your .htaccess file:

<ifModule mod_headers.c>
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>

Open in new window


I see this everywhere, but I don't understand it. What's the difference between the code above and this:

<ifModule mod_headers.c>
     Header set Cache-Control "no-cache, no-store"
     Header set Pragma "no-cache"
</ifModule>

Open in new window


In my opinion you could use the last one. There is already "no-cache", so there will be anyway (re)validation. So "max-age=0", "must-revalidate", and "Expires" makes no sense to me?

So for what reason exactly people are adding those things to the .htaccess file?
ASKER CERTIFIED SOLUTION
Avatar of Dr. Klahn
Dr. Klahn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Maarten Bruins
Maarten Bruins

ASKER

Ah thanks! I already thought, maybe there is some reason I don't know about. I also did tests with the Back/Forward button in Firefox and Chrome and I did not see any difference. And theoretically anyway it does not make sense.

Kind of weird to see how people are just copy / pasting (especially in tutorials) without thinking. But nothing to do about.

Thanks anyway for the explanation and quick answer!
I can not leave the question open? I think this is the right answer, but if someone wants to add something more then it's not possible anymore, because the topic is closed? Looks kind of weird to me ...