I'm trying to prevent out of view images from loading straight away. I've found what seems to be an accepted that involves putting the image src in another attribute then moving this into the src attribute when the image is required to load.
I'm inserting some images in javascript
'<img src="img/grey.png" data-original="'+image.src+'" />'
In Chrome DevTools however I can see the images being loaded (before I've even implemented the code to load them).
Why is this and how can I avoid them being loaded entirely?
I'm running with cache disabled.
More Details:
The images are coming from RSS feeds loaded by Google Feeds API.
feedpointer.load( function (result) {
if ( !result.error ) {
$.each( result.feed.entries, function (e, val) {
tempContent = $( '<div>' + val.content + '</div>' );
image = tempContent.find( 'img' );
$('.col_'+id).html('<img src="img/grey.png" data-original="'+image.src+'" />');
});
}
}
That's the gist. I can see with DevTools that the image is absolutely nowhere else on the page. I don't think the Feed API will load them as they're contained in text.
I believe tempContent = $( '<div>' + val.content + '</div>' );
might be the offending code making the images load. Is there an alternative to be able to traverse a string as DOM?