I did a lot of research about this problem, but with no success.
Essentially what I want to do is this:
1) Replace the src- attribute of all images with a placeholder, like 'blank.gif'
2) Add the HTML5 data-original attribute with the original image location
3) Lazyload the images (it needs the data-original attribute to work properly)
What I tried without success:
1) attaching this eventlistener document.addEventListener('beforeload', doBeforeLoad, true);
with this function
function beforeload() {
var blank = 'image/location/images/blank.gif';
$('img').each(function() {
var orig = $(this).attr('src');
$(this).attr('data-original',orig);
$(this).attr('src',blank);
console.log("changing all data on images");
});
}
2) on document.ready sure it won't work..
I have no idea if this is even possible, so any help | suggestion | resource would be greatly appreciated
PS: for example I want to make it work here) (because it's a image-heavy article )
That technique was used in older browsers with luck, but now modern browsers are not longer cheated with this way, so you have to do blank src and data source attribute on server side, here is popular jQuery lazy load plugin homepage, http://www.appelsiini.net/projects/lazyload you bet they did a lot of researches before writing this
UPD: just think over a bit and probably better approach to data- attribute would be using
noscirptwrapping for images you do want loaded lazlily here roughly illustration for idea http://jsbin.com/uqomeb/2/edit I would possibly do simple jQuery plugin later based on this