In my HTML page I load about 40 images from the same domain (on page start up, all images load at same time). The problem is, sometimes some images don’t show up, they’re just a white box with a red X on the top left side. But if I try to refresh the page once (or a few times), that image then loads fine.
Does anyone know why this happens and how to ensure all images load fine?
This happens because the images aren’t finished loading in time. You could try pre-loading them with javascript
What I would do is make sure the images are small (using thumbnails) so they will load. Then, load only a few at a time and load more as the page is scrolled or whenever the user requests more images.
See google images or pinterest for an example of how it would work. As you scroll the page, more images are loaded, as opposed to loading them all at once.