My site loads images based on names that are created for them. It loads images assuming that they’re there when sometimes they’re not. Every time it loads an image like this:
<img src="/myimages/my-image.jpg" alt=""/>
if it’s not there on the server, it seems to cache that there wasn’t an image there, so next time I load up the same image after my-image.jpg has been saved to the server, it just shows up as blank… How can I make it so that it’s not caching images that it doesn’t find?
Edit: I still want to cache images that it finds
OR
Alternatively, how do you check that a file exists? (preferably from javascript). That way I could check if the image exists before loading it and I would completely subvert this problem.
Thanks,
Matt
If you are able to, check from the server before the HTML file is ever sent to the client.
If this isn’t an option, you can use ajax: