Random image swap every 60 seconds
Posted on 2006-11-04
Currently at every load of a page, I run banner.cfm which cfincludes the following code and displays a different image:
<td height="100" rowspan="2">
<!--- banner.cfm --->
<div style='width:500px; height:100px; background-image:url(
<cfparam name="imageswap" default="#randrange(1,3)#">
imageswap is "1"><img src="image1.jpg">
<cfelseif imageswap is "2"><img src="image2.jpg">
<cfelseif imageswap is "2"><img src="image3.jpg">
There are nearly 100 images so I made my example short. It's crude but it works okay, as it is. But I'd rather make the random effect less random by displaying the same image on any page load for at least one minute, for everyone who hits the website, then load another. This way I also avoid excessive hits to the system, and the same image is already loaded into the client browser. Perhaps some kind of session id associated with banner.cfm? So, what would I have to modify with my code to get this idea working?
I'm also wondering if running through 100 cfelseif may be a problem. SQL and CF both have cache set, so perhaps not, but I'm wondering about this too. Maybe there's a much more efficient way to do this...?