简体   繁体   中英

How long does it take an image to fail?

If my page contains images with urls on other domains. How long does it take that image to fail if the domain does not respond?

Is it browser dependent?

Currently once an image errors out, I replace the URL with a fail image so I know that it failed.

The image is in fact on the other domain, but it seems to take a while to serve it. These images are favicons.

Here it the klass method that handles the repalcement:

init: function () {
    window.addEventListener("error", function (event) {
        if (event.target.tagName === 'IMG') {
            event.target.src = 'arcmarks/images/image_fail_50.png';
            event.preventDefault();
            event.stopPropagation();
        }
    }, true);
},

If I were you I would proxy this through my server and use the header status of the remote HTTP response and return a placeholder for anything != 200 .

Could you not use XHR to determine this before adding it to the page?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM