Cancel single image request in html5 browsers

后端 未结 4 2074
臣服心动
臣服心动 2020-11-30 06:06

I\'m loading (large) images dynamically to draw into a html5 canvas, something like this:

var t = new Image();
t.onload = ...
t.src = \'http://myurl\';
         


        
4条回答
  •  感情败类
    2020-11-30 06:41

    I have same problem actually and made some tests.

    I have made some tests with iframes and have some success. Tested on Firefox 3.6 and Chrome. For the tests I used 9 images of 15Mb. With img preloading I killed my firefox several times (yes, not much memoty on this computer), using img the "suspend" action does not prevent image loading if the request have started, with iframes the suspend action really stop the download (as I remove the iframe). Next step will be testing with XMLHttpRequests. As this version of my test code is using the braowser cache behaviour form the image url to prevent a second loading and this works as well with ajax requests. But maybe with iframes I could find a way to retrieve binary data from the loaded image in iframe directly (with limitation on same domain urls).

    This is my test code (really fast on Chrome, may kill your firefox with too much very big images):

    // 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('').attr('name', name).attr('id',id);
        var loader = jQuery('