Monday, April 27, 2009

Avoiding Browser cache

When I tried for first time to acheive this, It didn't work. Even meta-tags inside head tag didn't work.
Finally this worked after few permutations... The trick is to add these lines even before HTML tag. I guess that these headers are respected by browsers when they see it before HTML content.

response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", -1);.

This works for sure... If anybody knows more cleaner solution, please do let me know...

Sources: You can find this information any JSP book. I dont remember where I got the tip to Adding these before html tag.