Persits Software, Inc. Knowledge Base Articles

HOWTO: Force image refresh

Problem Summary

A page containing an image with a fixed name such as

<IMG SRC="images/photo.jpg">

is usually displayed with a cached version of photo.jpg even after a new image under the same name is uploaded to the server.

This article offers a simple trick to force an image refresh.

Solution

To force an image refresh, the SRC attribute of the <IMG> needs to assume a new and unique value with every page refresh. Since the image name is fixed, the changing part should be appended to the filename with the ? character used as a delimiter. In VBScript, the Rnd and Randomize functions can be used to ensure uniqueness, for example:

<%
	...
	Randomize

%>


<IMG SRC="images/photo.jpg?<% = Rnd %>">