desandro / imagesloaded

:camera: JavaScript is all like "You images done yet or what?"
https://imagesloaded.desandro.com
MIT License
8.89k stars 1.15k forks source link

Image corrupt or truncated error in Firefox when trying to load lots of big images #247

Closed carlotrimarchi closed 6 years ago

carlotrimarchi commented 8 years ago

Hello, I'm using this plugin to preload a lot (abot 70) of big images (for a total of about 30M) to use in an animation. It works perfectly on Chrome, but it fails on Firefox. At every page reload some images, usually 5 or 6 and often different ones, are not loaded. Looking in the console the error message "Image corrupt or truncated." is displayed.

Searching a bit around it appears to be a known and old bug in Firefox, just to say that I'm aware it is not the plugin's fault. Still, I'm wondering if there is a way to configure the plugin in order to avoid this issue.

While trying other solutions, I came up with something like this:

var images = $container.find('img');

var counter = 0;
var interval = setInterval(function () {
    if (counter === images.length) {
        clearInterval(interval);
     }
     for (var i = counter; i < counter + 5 && i < images.length; i++) {
         $(images[i]).attr('src', $(images[i]).data('src') + '?' + Math.random());
     }
     counter = i;
   }, 2000);

Before doing this, I also had to set all the src attributes to '#'. With the right interval it works, but at the end wasn't a good solution because messed up other stuff and actually on Chrome didn't work so well.

Still, is it possible to set a delay on the plugin to ease the loading? Do you think it can actually solve the problem or that wouldn't work either?

desandro commented 6 years ago

Thanks for reporting this issue. Looks like no one else chimed in so I'm going to close this one now. 🌈🐻