Website does not update in real time, cache problem

0

My website does not update at the same time that I modify a file, it takes a lot of time for the modifications to appear, I've already tried by means of GOALS TAGS, .manifest file, and Pragma in PHP. Unsuccessfully.

Just when I add "? v = 2" for example, it updates, I did it dynamically, because if I update the file, the "? v = 2" is already outdated and I have to use "? v = 3". It does not happen with all hosting sites.

LINUX Server with PHP 5.4.x.

    
asked by anonymous 13.03.2015 / 23:48

2 answers

1

If the pages you refer to are PHP files, they are usually not cached (from browser to browser), to avoid caching, create a file named global.php and add the following content:

<?php
$g = gmdate('D, d M Y H:i:s');
header('Expires: ' . $g . ' GMT');
header('Last-Modified: ' . $g . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

And use include to add this file to all your required PHP files, for example in index.php

<?php
include 'global.php';

...Resto arquivo...

Pages that are already cached will continue to expire, but as they expire they will never be cached again.

But I'll be honest, if they are PHP files it is very likely that you are already using headers to cache, maybe you are using some framework and this has no way of responding.

Another possibility is that there is some .htaccess file that is causing this.

If the code above quoted does not work please edit your question and add details. Hope it helps.

If the case is of static files, such as .js , .css , .html , .jpg , etc. you can use .htaccess itself to prevent caching (although I do not recommend it, since static files rarely have modifications and it would be best to use caches in them). Example ( SOen ):

<filesMatch "\.(?i:html|htm)$">
  FileETag None
  <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</filesMatch>

In this example only the file .html and .htm will not be cached.

Reported: If-modified-since can be used with "304 not modified "Without PHP

    
21.06.2015 / 21:50
0

try using this script was with a similar problem and resolved

<script>
$(document).ready(function(){
setInterval(function(){cache_clear()},3000);
});
function cache_clear()
{
window.location.reload(true);
}
</script>
    
14.03.2015 / 00:10