toddmotto / echo

Lazy-loading images with data-* attributes

Home Page:http://toddmotto.com/labs/echo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

_inview function has a flawed assumption

ErtugKaya opened this issue · comments

If a user scrolls down to a page that will work but what if he jumps to a point of page by clicking a link to an anchor or some other ways? All the images above that point will be loaded as well. This spoils lazy loading.

You should consider if image will be actually in viewport after lazy load, to load it. Easy to say, hard to make :)

These are pretty uncommon use cases though, I don't really want to bloat out the script to cater for every if, what if, and maybe.

With all due respect, I don't share your opinion of "uncommon use". Lazy loading is especially useful if you have many images in a page, like galleries or product lists. They generally have a filtering system to hide some images and show others. Images position and visibility may be changed by a script.

Also, many frameworks have page navigation like this http://getbootstrap.com/javascript/#affix

So load triggering should be advanced to handle those scenarios. I am sure that you agree, lazy loader should not load anything unnecessary. Just my two cents.

Thing is every use case may be different, and somewhat awkward. Position and things being changed by a script (not fired with scroll handler but needed to load) is a good shout. A recursive setTimeout() when the user stops scrolling to fire at an interval might be a really good shout.

Might be cool to return a public API, called Echo.apply(); or something, to refresh the script and run again based on a view change/response. That way people could use it inside callbacks.

Integrated in latest update.