Hi there, and apologies if this is a rather long-winded answer...
Fabian said:
Fabian wrote:
var preload1 = new Image(); preload1.src = "/pic/yay.gif";
var preload2 = new Image(); preload2.src = "/pic/nay.gif";
The above is meant to preload image files, yes?
Yes, [...SNIP...]
The images in question at < 3kb each, and the page wont make sense if
they dont get displayed.
Problem is, it doesnt seem to be doing so in practice.
How do you get that idea? [...SNIP...]
No errors I can tell anyway.
Because there's no code there to detect the error that's happening ...
Its at
Actually I found at
www.lajzar.co.uk/en/animals.html
(amongst others) if you want
to look. Since I have no idea where in the code a bug of this kind might
reside, it seems pointless posting any in the group at this stage. The
prime suspect was apparently the wrong one.
It's not a javascript problem...
Id have hoped I would at least be able to modify this particular user's
cache settings to enable preloading.
I do not believe the user's browser cache settings have anything to do
with whether the images "preload"
No. Don't believe so ...
But here's what happened when I tried loading the "animals.html" page:
1. Browser requests animals.html
2. Server says 200 ok, here it is
3. Browser sees it needs css.css & requests it
4. Server says 200 ok, here it is
5. Browser requests "favicon.ico"
6. Server says 200 ok, here it is
[ don't get bored yet ...]
7. Browser sees it needs "game1.js" and requests it.
8. Server says 200 ok, here it is:
Note, your Apache server serves this as application/x-javascript.
This is probably as ok as anything, but it may be more usual to serve it
as text/javascript. Though this has nothing to do with the problem.
[This is the interesting part:]
9. Browser sees it needs yay.gif and requests it
10. Server says 404, can't find it (!!)
11. Browser sees it needs nay.gif and requests it
12. Server says 404, can't find it (!!)
Has nothing to do with cache; has to do with the server can't find the
images to serve. They are being requested as /pic/yay.gif (or
/pic/nay.gif) from
www.lajzar.co.uk
When you call the checkAnswers() function, you construct the yay/nay
image sources as
"pic/yay.gif"
"pic/nay.gif"
That is, without the starting "/". In this case the images show. So the
answer is that in your preload code you're trying to fetch the images
from the wrong place.
I think you can put an onerror event handler on the image preloads to
detect the error:
preload1 = new Image();
preload1.onerror=function(){alert("No Preload-yay");};
preload1.src = "/pic/yay.gif";
ALthough that's not very pretty. And as you've coded the checkAnswers()
function (with the correct image location) the problem fixes itself
(even if image showing might not be as fast as you'd like).
HTH,
Stephen