airfranceklm / ng-lazy-image

Angular directive for loading responsive image when container (which is preventing reflow) is in viewport.
http://afklm.github.io/ng-lazy-image/
MIT License
351 stars 64 forks source link

Empty requests to server being made due to images with empty src getting appened to dom #20

Closed darrenvng closed 8 years ago

darrenvng commented 8 years ago

I noticed extra calls being made to the server when new groups of images are lazy loaded as I scroll down my site. I believe it is being caused by images with empty image sources getting appended to the dom before they are eventually replaced by the lazy loaded url src.

I think in this file lazy-image.directive.js, on line 132, maybe you can set a src of 'about:blank' or 'javascript:void(0);' to prevent the extra request to the server. Or maybe to delay appending the element to the DOM until you have the lazy loaded url src ready.

Thanks, Darren

SquadraCorse commented 8 years ago

Do you output the directive without a known src (in other words is that your usecase)? At the moment i'm testing without starting with empty source (which is invalid html i know <img alt="foo" />). Other options mentioned have too many browsers issues, will try datauri but need browserfarm to test this.