-3

I want to lode my web site every time in every browser with NO CACHE so i tried to do it through HTMl and PHP guided from here` How to control web page caching, across all browsers?

PHP

header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.



HTML

<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" />

and in the result i can see that in the response all parameters set properly

enter image description here

but still I can see that the web site loading old img from cache

as when i putting on the function of browser "Disable the cache when developer tool opened" i really can see how images are loading normally from server.

My question is how to avoid this ? and be sure that it is every time will load all from server ?

In addition the thing is that i can not do it trough htaccess as i need to have something like this http://url.com/?noCache=true and if it is anything else than it should load normally from cache

Community
  • 1
  • 1
VostanAzatyan
  • 418
  • 8
  • 19
  • Can you try it from `incognito` or `private` mode ? – Sulthan Allaudeen May 25 '15 at 06:59
  • 1
    The images are served directly from Apache, your php code is not called in that case. – SharpEdge May 25 '15 at 06:59
  • Your provided header will not affect images. Only possible by appending a random number with every images like – Samir Das May 25 '15 at 07:01
  • I know about this solution but this is the only why to do this ? i suppose there are some global solutions as well – VostanAzatyan May 25 '15 at 07:03
  • Please explain why down vote ? what is wrong with this question ? – VostanAzatyan May 25 '15 at 07:30
  • I haven't downvoted but I suspect the title and choice of tags might be to blame, your question is reasonable (I would search SO again though, very similar problems have been covered many times). The question title could perhaps be called something less broad: "How can I ensure my site images are always fetched from the server?" No need to mention php in the title just tag appropriately. Remove the javascript tag as your question makes no mention of it, add an apache tag instead as this might draw more useful answers. Tidy up your question and you'll likely attract more upvotes and answers. – seanhodges May 27 '15 at 03:24

2 Answers2

0

You can try this my code that I use everyday without problems...

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Date In The Past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # Always Modified
header("Cache-Control: no-store, no-cache, must-revalidate"); # HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); # HTTP/1.0

and then in html head I have only this...

<meta name="pragma" content="no-cache">

And this combination of php/html works for me great. I hope my answer helps you to solve your issue!

Alessandro
  • 771
  • 8
  • 21
0

I've got the same problem when i make Facebook Tab Application with multi-lingual support, so when user click to switch between languages it also changes CSS files for each language for that i need to tell browser to re-validate cache i use this code:

<IfModule mod_headers.c>
  Header set Cache-Control "no-cache, no-store, must-revalidate"
  Header set Pragma "no-cache"
  Header set Expires 0
</IfModule>
Touqeer Shafi
  • 4,418
  • 2
  • 23
  • 41