views:

137

answers:

3
+1  Q: 

IE history

Hi there

I generate some png charts and excel files using a mysql database. I display the charts as images in my webapplication, but from time to time IE users don;t have acces to the last version of the files because IE keeps showing to them the previous loaded datas(charts and excel files)

How to prevent happening that? On the client side what can be done?

My web-application is written in PHP. What approach should i use in order to force IE to load the new files?

+2  A: 
<HTML><HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD><BODY>
</BODY>
</HTML>
dogbane
+5  A: 

Another approach you can use is to add a unique query string to the images you're showing. On the image handler, you can ignore the data that is actually passed on the query string, but IE will treat URLs with different query strings as being unique and therefore require loading each one anew without using a cached version.

For example, changing:

<img src="mychart.png>

to:

<img src="mychart.png?timestamp=0512200911090000">

will get you to avoid the IE cache.

JoshJordan
You don't even need the 'timestamp=' bit, just 'mychart.png?0512200911090000' will work.
swilliams
True of course, but the concept is easier to illustrate with a pair because it shows how to make the query string unique instead of static.
JoshJordan
+2  A: 

HTML meta can work, but using PHP headers are efficient and more correct (look here). The article covers caching downloadable/not html files too.

Caching can be done one of these ways in PHP (use headers before streaming the content of the image):

<?php 
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
    header('Pragma: no-cache'); 
?>

or

 <?php 
     header('Expires: Mon, 26 Jul 1997 05: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'); 
 ?>
boj