Jump to content

Best practice to prevent browsers from loading contents from cache


pideluxe
 Share

Recommended Posts

What is you best practice for preventing web browsers from loading contents of newly generated or static sites from their cache, so that the visitor always gets the newest version? I tried the following, but not with the desired results:

  • Meta-Tag "expires" with date in the past
  • .htaccess-method described here (german)

Any suggestions?

Link to comment
Share on other sites

Try this:

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

Or this with sunday as example:

<meta http-equiv="expires" content="Sun, 01 Jan 2014 00:00:00 GMT"/>
<meta http-equiv="pragma" content="no-cache" />

header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');

You can also do random Generated Numbers on the files you dont want to be cached.

  • Like 3
Link to comment
Share on other sites

 Share

×
×
  • Create New...