Jump to content
pideluxe

Best practice to prevent browsers from loading contents from cache

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By FrancisChung
      Hi there,
      I'm experiencing a real weird caching issue with Safari (Desktop) and all mobile browsers where it is loading the old version of the site and refusing to reload the website.
      I don't seem to have the problem with Chrome where a reload did correctly reload the latest version of the website.
      Has anyone come across this issue before?
       
      Things I have tried (and failed) :
      1) I've replaced our .htaccess file with the standard one that comes with Processswire 2.8
      2) Everything here
      https://stackoverflow.com/questions/1922910/force-browser-to-clear-cache
      3) Deleted everything under /assets/pwpc folder. 
      4) Deleted all local wesbite data on laptop/mobile and reloaded.

      Much appreciate if anyone can help me 
×
×
  • Create New...