[thelist] image caching
Jeff
jeff at members.evolt.org
Thu Apr 6 03:27:04 2000
peter,
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Peter Van Dijck <peter@vardus.net>
:
: I have this page where people can change the image
: related to a database row. The name of the image stays
: the same.
:
: but when they reload the page to see the new image, it's
: cached ofcourse and the old one shows up.
:
: I can't find a way to fix it, all I can think of is having some
: javascript emptying the browsers cache. Is that possible??
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
there are several ways to do this.
one would be to set the no-cache header for the page. that's not a really
good solution though as that would mean that the page and all elements on
the page would have to be loaded from the server every time.
you could tell the users that they have to SHIFT+Reload the page, forcing
the browser to get the page and all it's elements from the server. this is
good because it only happens when it needs to and not every time. it's bad
though because it requires user intervention, something users aren't
generally very good at.
something else you could try is appending a random number to the end of the
image source string. the browser will think, because of the query string,
that it should check for a new version. here's an example of how i might
handle it.
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function freshImage()
{
if(document.images)
{
ts = new Date().getTime();
document.images['sample_image'].src =
document.images['sample_image'].src + '?' + ts;
}
}
window.onload = freshImage;
// -->
</SCRIPT>
then, you'd have your problem image on the page like this:
<IMG
NAME="sample_image"
SRC="image/some_db_row.gif"
HEIGHT="50"
WIDTH="200"
BORDER="0"
ALT="sample image">
good luck,
.jeff
name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff@members.evolt.org