I have a large background image in my website, and some times the background image doesn't load.
It shows this error in console:
GET http://www.mywebsite.com/wp-content/uploads/2017/01/cover_background.jpg 404 (Not Found)
If I right click the link and "Open in new tab", or refresh the page, the image shows correctly.
This seems to be some kind of resource request error server-side, right?
I wanted to find a way in jQuery to:
- Check if the image was loaded correctly
- If it didn't, reload that image alone
PS: I've seen some AJAX methods for getting the image header and check if it returned 200 or 404, but I don't think this would work in my case, because that AJAX call would be another request to the server, and the server might return a 200 status to AJAX, even though it returned 404 when loading the page.
PS 2: It's not duplicated. That's raw. This is final product. In that question it doesn't specify that you need to set a DIFFERENT image on error, a backup image. It just references the same image again.