vvo / lazyload

:bullettrain_front: Lazyload images, iframes, widgets with a standalone JavaScript lazyloader
https://vvo.github.io/lazyload/
MIT License
938 stars 158 forks source link

Infinite loop when 404 #62

Closed kud closed 10 years ago

kud commented 10 years ago

404-lazyload

(sorry for the bad quality)

vvo commented 10 years ago

Thanks for posting this, looking at it.

vvo commented 10 years ago

@kud I cannot reproduce it byt using the current version.

Here's what I have tested: using the https://github.com/vvo/lazyload/blob/master/examples/simple.html I change the uri of one image to a 404 one and then there's no infinite loop.

Do you have a 404 on the blank.gif or one the real image?

vvo commented 10 years ago

Browser ? Brower Version ? System ? Lazyload version ?

kud commented 10 years ago

"lazyload": "git://github.com/vvo/lazyload#2.1.1" via npm

kud commented 10 years ago
<img data-src="img.png"
    src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
    onload=lzld(this) onerror=lzld(this)>

I'm pretty sure it's because of onerror, right?

vvo commented 10 years ago

oh yes that may be the case.

But with current version, using google chrome, using the simple example. Adding an onerror + changing to bad src result in no loop.

--- EDIT ---

I see the loop now


Onerror is only needed for IE8 compatibility when using data-uris (data uri generates an onerror so we then use it to know the blank image "loaded".

Either drop IE8 support Or use a b.gif and drop onerror handler

vvo commented 10 years ago

Ok found a fix and will publish it, thanks a lot @kud

kud commented 10 years ago

;)

vvo commented 10 years ago

done @kud, published as v2.1.3 let me know

kud commented 10 years ago

Thanks :D

fritx commented 10 years ago

Hello @vvo I find that this change disables custom onerror on <img> tags

vvo commented 10 years ago

@fritx even when using addEventListener?

fritx commented 10 years ago

@vvo haven't tried addEventListener but I had to use onerror :cry:

vvo commented 10 years ago

For what do you need onerror on lazyloaded images?

fritx commented 10 years ago

@vvo my teammate had an onerror="setMissingPic(this)", so we had to keep it.. How to deal with it without modification on your lib? :smile: ---- EDIT ---- And I tried to drop this change It works but I don't know well what's the side-effect

vvo commented 10 years ago

maybe try onerror="setMissingPic(this);lzld(this)"

and in setMissingPic set a new data-src.

Otherwise you can build your own lazyloader using https://github.com/vvo/in-viewport

Otherwise we would need to change the library

fritx commented 10 years ago

Thanks for your tips ;)