Search Persits Software Knowledge Base

 

Article PS070307161

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

Created: 3/7/2007 6:30:41 PM
Last Modified: 3/7/2007 6:30:41 PM

Copyright © Persits Software, Inc. 1998 - 2018
For technical support, write to support@persits.com.