I have a very long page that dynamically loads images as users scroll through.
However, if a user quickly scrolls away from a certain part of the page, I don’t want the images to continue loading in that now out-of-view part of the page.
There are lots of other requests happening on the page simultaneously apart from image loading, so a blunt window.stop() firing on the scroll event is not acceptable.
I have tried removing & clearing the img src attributes for images that are no longer in view, however, since the request was already started, the image continues to load.
Remember that the image src was filled in as the user briefly scrolled past that part of the page. Once past though, I couldn’t get that image from stop loading without using window.stop(). Clearing src didn’t work. (Chrome & FF)
Similar posts I found that get close, but don’t seem to solve this problem:
What you are trying to do is the wrong approach, as mentioned by nrabinowitz. You can’t just “cancel” the loading process of an image (setting the
srcattribute to an empty string is not a good idea). In fact, even if you could, doing so would only make things worst, as your server would continually send data that would get cancelled, increasing it’s load factor and slow it down. Also, consider this:Often, computer problems are simply design problems.
** EDIT **
Here’s an idea :
your page should display
DIVcontainers with the width and height of the expected image size (use CSS to style). Inside of eachDIV, add an link. For example :Add this Javascript (untested, the idea is self describing)