简体   繁体   English

图片失效需要多长时间?

[英]How long does it take an image to fail?

If my page contains images with urls on other domains. 如果我的页面包含其他域上带有URL的图像。 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. 目前,一旦图片出现错误,我将URL替换为失败的图片,以便知道它失败了。

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: 这里是处理补给的klass方法:

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 . 如果我是你,我将通过服务器代理它,并使用远程HTTP响应的标头状态,并为任何内容返回占位符!= 200

Could you not use XHR to determine this before adding it to the page? 在将其添加到页面之前,您能否使用XHR来确定它?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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