3

The title might be kind of bad or misleading but here is my question:

Is there a good way to make sure that if someone has visited my site in the past and then revisits it after some time, the old content won't be showing and the new content is there instead?

mhu
  • 17,720
  • 10
  • 62
  • 93
user1826795
  • 195
  • 1
  • 1
  • 8
  • In your question (and the tags) is not clear if you're using memcached or any other library to keep cached pages on server side. – Alfabravo Apr 23 '13 at 14:13
  • I hope this would help you.http://stackoverflow.com/questions/6816017/cache-control-and-expires-header-for-php – dreamweiver Apr 23 '13 at 14:14

3 Answers3

3

I add something like this to my php - be sure to send headers before you write out anything else....

  header("Cache-Control: no-cache, must-revalidate"); 
  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); 
Al.
  • 330
  • 1
  • 13
  • Note: I don't develop for public systems, so you may find you need to add extra headers to cover all browsers - try some testing. – Al. Apr 23 '13 at 14:15
1

Use http header entries to turn off caching:

<head>
    <meta http-equiv="Expires" content="0" />
    <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate" />
    <meta http-equiv="Cache-Control" content="post-check=0, pre-check=0" />
    <meta http-equiv="Pragma" content="no-cache" />
</head>
dstronczak
  • 2,406
  • 4
  • 28
  • 41
1

The reason why old content might be shown is that it has been cached. And user's browser might take the content from cache. If it is not cached then user would get the new content every time he or she opens the site in browser.

I guess you want to have an option to force user's browser to show updated page even when the browser has the page in the cache. The page still might be cached but when you have new version you want user to see the new version.

I suggest to consider the following approach. You can add parameter to the page URLs on site and change this parameter when the content is changed. For example:

http://example.com/code.js?version=22

I use this approach for CSS and JS files. Normally they should be cached for long time may be for weeks or months. But when the file is updated user should get the new version.

This has nothing to do with normal cache control. But solves the task when you want you files and pages be cached and control when they should be updated.

Please let me know if you have any questions.

Victor Smirnov
  • 3,450
  • 4
  • 30
  • 49