33

I have a HTML page. The problem is that I do not want to have the users to refresh the page each time I put on new content.

I have the following code in order to make sure that the page is not cached:

     <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"/>

The problem is, I still need to do a refresh on the page in order to get the most current content to show up. Am I doing something wrong? Should I be using some other tags?

Nate Pet
  • 38,422
  • 114
  • 251
  • 393

2 Answers2

30

The Codesnippet you showed makes the browser load the website everytime it accesses it, which is useful if you perform frequent updates, but still have a static page.

<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"/>

In case you want it to perform live updates, like it does for example in a (g)mail account, you need to make it refresh (parts of the page) itself. Use Javascript in this case, like it is shown in this question or an ajax call.

$('#something').click(function() {
    location.reload();
});
Community
  • 1
  • 1
Garrin
  • 521
  • 1
  • 3
  • 8
  • Garrin, I have an HTML page and yes, I make frequent updates. As such shouldn't work? It seems like I still need to do a refresh – Nate Pet May 23 '13 at 15:09
  • I still not surely know what you need/want to do. If you really need **live updates** while the user is still watching your page, you have to go for the Javascript/Ajax solution. But if you want the user to have the latest version of the website **everytime he visits it**, like if you update your website daily, your solution is good enough. – Garrin May 23 '13 at 15:14
  • 1
    The reason is we are making updates to the html page which is a static page. We make these every 2 days. I like the user to see the latest version of it instead of clicking on refresh. – Nate Pet May 23 '13 at 15:16
  • I read a bit about it and according to [this question](http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers) your snippet seems to be complete. I'm sorry if I couldn't help in this case. – Garrin May 23 '13 at 15:35
  • Does this work for HTML5 web pages? – ayjay Aug 04 '14 at 04:13
  • 1
    Does this work for the HTML files itself only, or also all referenced sources? Also, does this work for HTML5 too? – Benny Bottema Feb 26 '15 at 12:45
  • @Plantface Yes, HTML file only. All referenced sources would each need to return similar HTTP response headers. Each referenced source is a separate HTTP request. Any version of HTML. But this is really an HTTP protocol thing, rather than HTML. – MrWhite Feb 21 '16 at 22:43
13

The values you have there are OK, but meta http-equiv is highly unreliable. You should be using real HTTP headers (the specifics of how you do this will depend on your server, e.g. for Apache).

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205