View Full Version : Preloading Dynamic Images

02-26-2003, 07:02 PM
Now this is a weird problem indeed. I have what could be 4
separate technologies to make a menu bar for my website. The
page includes both html and php. The php exectutes a perl script
which loads the trees blah blah blah and returns some
javascript/image code. The images point to another php page
which dynamically loads the name of the link over 3 basic images,
the normal/hover/active images. The javascript "preloads" the
images and then swaps them over using the
onMouseOver/onMouseOut events.

The problem. Despite the fact the images are preloaded and
stored into image objects, the dynamic-image php
script "navbar.php" is called whenever the images are swapped.
Obviously this is hopless cos theres a massive delay, and the
load on the server is immense.

Here is the preloading function, practically lifted from the code
generated by m$ frontpage.

function preload(source)
var a=new Image();
return a;

The following is then an extract from the perl script which writed
the image/links

print <<END;
var $state$x = preload("http://$ENV{HTTP_HOST}/navbar.php?text=$disp{$tree[$x]}&state=$state");
var Hover$x = preload("http://$ENV{HTTP_HOST}/navbar.php?text=$disp{$tree[$x]}&state=Hover");
print "<a href=\"", $root, $def{$tree[$x]}, "\"
name=\"img$x\" src=\"http://$ENV{HTTP_HOST}/navbar.php?
text=$disp{$tree[$x]}&state=$state\" border=\"0\" /></a>\n";

I have proven the image swapping does not use cached images
because i renamed the navbar.php file and the image changed to
the icon for "cannot find image". Hope someone out there can
help. It really is not practical to have the php generate a new
image each time someone passes a mouse over the link

thx in advance

02-28-2003, 12:23 AM
C'mon, you ppl gotta have an answer to this problem by now!!!