-3

Now this bug has lasted long enought. I have tried everything to stop the caching. Everything on the following stackoverflow links:

Chrome - Disable cache for localhost only?
Disabling Chrome cache for website development
Using <meta> tags to turn off caching in all browsers?
How to prevent Browser cache for php site
How to control web page caching, across all browsers?
How to prevent http file caching in Apache httpd (MAMP)

And also i tried to rightclick on the reload button on chrome and choose reload page complete and empty cache and reload page completely. I use PHPStorm as IDE but i also tried switching to notepad++ in case PHPStorm wasn't saving the file properly. Tried setting timestamps in the header so my requests to the page isn't identical. I am running on localhost XAMPP. Any solutions/ideas/guesses are more than welcome.


Note

Restarting XAMPP actually clears the cache (or at least forces the browser to reload the content). I have no idea why. Thanks in advance


Note

My PHP codes are being cached as well. When i edit my PHP codes and i refresh the page, it runs the old codes again. It's probably because the browser still shows the cached version of the page but thought it was worth mentioning.

131
  • 1,285
  • 1
  • 12
  • 30

4 Answers4

2

There isn't much info here; but you might want to have a look at your php.ini and especially your revalidate_freq. It should preferably be 0 for development; but definitely not bigger than then default of 2 seconds.

Sjon
  • 4,605
  • 6
  • 24
  • 42
1

Create a .htaccess file under root directory and put the below code inside .htaccess file. check if you have mod_rewrite enable in the server (optional). Add it stops caching the pages

#Initialize mod_rewrite
RewriteEngine On
<FilesMatch "\.(html|htm|js|css)$">
  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, 12 Jan 1980 05:00:00 GMT"
  </IfModule>
</FilesMatch>
mka
  • 15
  • 7
1

Please check below mentioned solution, It will help you.

Step 1:

In HTML head tag you should add below mentioned lines.

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>

So with this when user visits your page, every time new content will fetch from server.

Step 2:

By using .htaccess you can prevent page 100% being cached by browser.

<filesMatch "\.(html|htm|js|css)$">
  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>

Step 3:

If your page is in PHP than add this line on the top of the page.

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");
header("Expires: 0");

Let me know if it not works.

Shyam Shingadiya
  • 3,227
  • 1
  • 19
  • 36
0

i install a chrome Extension that clear cache. i config it to clear cache with CTAL+Q - so insead of refresh page with F5 or CTRL+R i use this Extension - it solve my developin cache problems ( i use polymer framework - and i have same problems as you ) i use this extension

yehonatan yehezkel
  • 742
  • 12
  • 19