If the pages you refer to are PHP files they usually don’t cache (ranging from browser to browser), to avoid caching create a file called 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 on index.php
<?php
include 'global.php';
...Resto arquivo...
Pages that are already cached will continue until they expire, but once they expire they will never be cached.
But I’ll be honest, if they are PHP files you are very likely already using "headers" to cache, maybe you are using some framework and this has no way to respond.
Another possibility is that there is some file .htaccess
that’s causing this.
If the above code I quoted does not work please edit your question and add details. I hope it helps.
If static files, such as .js
, .css
, .html
, .jpg
, etc. you can use .htaccess
to prevent caching (although I don’t recommend it, because static files rarely have modifications and the best would be to cache 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: It is possible to use if-modified-Since with "304 not modified" without PHP
Sorry, but I didn’t get it right, does the cache happen in the php file? Or in javascript? In which of the files are you modifying. If it is php, which framework are you using? Because who stores cache is the browser or the server, in the case of the server is either a config of the framework or is in the hosting settings.
– user1811893
Another chance, where are you testing? College, work? The company does not have its own cache system?
– user1811893
I changed server (Locaweb) and the problem persisted, however, I created another index.php with the same code, and this stopped caching, I no longer need to use ? v=X. Very strange. All indications were problem in the file. I will continue the tests.
– Fabio Weydson
Good evening Fabio, the answer solved the problem?
– Guilherme Nascimento
Managed to solve your problem?
– durtto
Got, just changing server even, is some cache configuration that even the support of the company can not cure me the problem.
– Fabio Weydson