0

I have question regarding disabling browser caching. I have already found few solutions, and just want to know if there are better or more common approaches. So I have GWT applications and in order to disable cashing I may use next options:

  1. Adding to URL dummy parameter
  2. Putting on the HTML page <meta http-equiv="pragma" content="no-cache">
  3. Setting HTTP headers:

    header("Pragma-directive: no-cache");  
    header("Cache-directive: no-cache");  
    header("Cache-control: no-cache");  
    header("Pragma: no-cache");  
    header("Expires: 0");
    
StuperUser
  • 10,555
  • 13
  • 78
  • 137
IgorDiy
  • 919
  • 1
  • 12
  • 25
  • It is already asked I guess. check this [link](http://stackoverflow.com/questions/2558779/how-to-programmatically-disable-html-caching-with-gwt) – AurA Apr 09 '12 at 11:23
  • 1
    The headers you list include some fantasy/wishful thinking. `Expires:0` is a syntax error, `*-directive` are nonsense, `Pragma: no-cache` is irrelevant since end of '90s. The only one that matters is `Cache-control: no-cache`. `` cannot work, since it's cached before it is parsed. – Kornel Apr 09 '12 at 11:28
  • So, i should use first option? But this is most inconvenient way for me. I'd rather use option number 3. – IgorDiy Apr 09 '12 at 11:32

1 Answers1

2

The most important are the

header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");  #Expires sometime in the past
header("Cache-control: no-cache");                 #Disables caching

In addition, add the unique parameter to the url to be sure. If you are using browser back-button sometimes the entire DOM is cached and no new content is fetched unless you do it dynamically using javascript and adding a unique id to your request.

Normally, you want to set most of these headers in your server configuration so that you can serve normal images and other static content with the right headers also.

jornare
  • 2,903
  • 19
  • 27