Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent IE caching

I am developing a Java EE web application using Struts. The problem is with Internet Explorer caching. If an user logs out he can access some pages because they are cached and no request is made. If I hit refresh it works fine. Also if an user goes to login page again it won't redirect him because that page is also cached.

Two solutions come to my mind:

  1. Writing an Interceptor (servlet filter like) to add to response header no-cache etc.
  2. Or or put <meta> tags at each page.

Which one should I do?

like image 211
GorillaApe Avatar asked May 17 '10 12:05

GorillaApe


People also ask

How do I stop Internet Explorer from caching?

Navigate to the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings registry subkey. From the Edit menu, select New, DWORD Value. Enter a name of DisableCachingOfSSLPages, then press Enter. Double-click the new value, set it to 1 to disable caching of SSL pages, then click OK.

Do browsers automatically cache?

Every time a user loads a website page, their browser downloads the page's data to show it. Just like website servers, browsers cache most content on a page to shorten load times. So, the next time that user loads the page, most of the content is ready to go without needing to download additional data.


1 Answers

Rather set the following headers on the HttpServletResponse of the page(s) in question so that you don't need to copypaste it over all pages manually:

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.

This is equivalent to setting the following meta headers in the page(s) manually:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

Also see this answer. Don't forget to clear browser cache before testing ;)

like image 100
BalusC Avatar answered Oct 05 '22 06:10

BalusC