我实际上有同样的问题并做了一些测试。
我已经用iframe进行了一些测试并取得了一些成功。在 Firefox 3.6 和 Chrome 上测试。对于测试,我使用了9 张 15Mb 的图像。通过 img 预加载,我多次杀死了我的 Firefox(是的,这台计算机上没有太多内存),如果请求已经开始,使用 img 的“暂停”操作不会阻止图像加载,而 iframe 的暂停操作确实会停止下载(因为我删除 iframe)。下一步将使用XMLHttpRequests进行测试。由于我的这个版本的测试代码使用了图像 url 中的 braowser 缓存行为来防止第二次加载,这也适用于 ajax 请求。但也许使用 iframes 我可以找到一种方法来直接从 iframe 中加载的图像中检索二进制数据(对相同域的 url 有限制)。
这是我的测试代码(在 Chrome 上非常快,可能会用太多非常大的图像杀死您的 Firefox):
// jQuery.imageload.shared.list contains an array of oversized images url
jQuery.each(imglist,function(i,imgsrc) {
name = 'imageload-frame';
id = name + "-" + i;
// with img it is not possible to suspend, the get is performed even after remove
//var loader = jQuery('<img />').attr('name', name).attr('id',id);
var loader = jQuery('<iframe />').attr('name', name).attr('id',id);
//no cache on GET query taken from jQuery core
// as we really want to download each image for these tests
var ts = +new Date;
// try replacing _= if it is there
var ret = imgsrc.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
// if nothing was replaced, add timestamp to the end
imgsrc = imgsrc + ((ret == imgsrc) ? (imgsrc.match(/\?/) ? "&" : "?") + "_=" + ts : "");
loader.css('display', 'none').appendTo('body');
loader.after( jQuery('<a>')
.text(' stop ')
.attr('href','#')
.click(function(){
loader.remove();
jQuery(this).text(' suspended ');
})
);
// start the load - preload
loader.attr('src',imgsrc);
// when preload is done we provide a way to get img in document
loader.load(function() {
jQuery(this).next("a:first")
.text(" retrieve ").unbind('click')
.click(function() {
var finalimg = jQuery('<img />');
// browser cache should help us now
// but there's maybe a way to get it direclty from the iframe
finalimg.attr('src',loader[0].src);
finalimg.appendTo('body');
});
});
});
编辑,这里是 fillde 来测试它:http : //jsfiddle.net/wPr3x/