4

If a resource (index.html) is already cached in the client, for example using response header:

"Cache-Control": "max-age=0, must-revalidate, proxy-revalidate"

How can I prevent tomcat to respond with a 304 Not Modifiedin the next request to the server? I would like to force the server to respond with 200 instead of 304 no matter what. I tried to set

httpResp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, proxy-revalidate");
httpResp.setHeader("Pragma", "no-cache");
httpResp.setHeader("Expires", "0");

but it only works in the SECOND request. The first request still gets 304. I tried to override the if-modified-since header using HttpServletRequestWrapper with values in the past such as Mon, 06 Dec 2010 01:34:46 GMT with no luck - client still gets 304 responses although the file was modified in 2015. Is there any way I can prevent 304 responses? maybe via tomcat configuration?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
user1116377
  • 511
  • 2
  • 10
  • 29

1 Answers1

0

Not sure if this will help but you could try the following -

  1. Delete the browser cache to start from scratch and test whether this works or not

  2. Adapted from another ServerFault question -

https://serverfault.com/questions/40205/how-do-i-disable-tomcat-caching-im-having-weird-static-file-problems?answertab=votes#tab-top

You might have to delete the application cache folder in /work/Catalina/localhost after changing the cachingAllowed flag. Configuration can be introduced in server.xml as

    <Context className="org.apache.catalina.core.StandardContext"
             cachingAllowed="false"
             charsetMapperClass="org.apache.catalina.util.CharsetMapper"
             cookies="true" 
             reloadable="false" 
             wrapperClass="org.apache.catalina.core.StandardWrapper">
    </Context>
Community
  • 1
  • 1
Sohail
  • 3,968
  • 1
  • 33
  • 36