A fork for Image lazy loader with the plugin cookie by Klaus Hartl/klaus.hartl@stilbuero.de. To use cache in images.
This example requires the server to the physical size of the image. For example a php.
$.iod = { time: "", speed : "", total : 0 }
$("img").lazyload({
placeholder : "http://www.appelsiini.net/projects/lazyload/img/grey.gif",
cache : true,
call: "$(self).attr('time', (new Date()).getTime());",
callback: ""+
"if ($.cookie($(self).attr('src')) != '1' && settings.cache == false ) {"+
"$.iod.time = ( (new Date()).getTime() - $(self).attr('time') );"+
"$.iod.time = ( ( $.iod.time >= 0 ) ? $.iod.time : 0 ) / 1000;"+
"$.iod.speed += String( ($(self).attr('size')/$.iod.time ).toFixed(0) ) + '/';"+
"$.iod.total -= $(self).attr('size');"+
"};"
}).each( function() {
$.iod.total += parseInt($(this).attr('size'));
});
$(window).unload( function () {
try {
pageTracker._trackEvent('ImageOnDemmand-Safe', String($.iod.total));
pageTracker._trackEvent('ImageOnDemmand-Speed', String($.iod.speed) );
} catch (err){
alert(String($.iod.total) + ": " + String($.iod.speed));
};
})






And the php server side (a wordpress plugin example)
function remote_file_size($url){
if ( ! file_exists($url) ) {
$parsed = parse_url($url);
$host = $parsed["host"];
$fp = @fsockopen($host, 80, $errno, $errstr, 20);
if(!$fp)return false;
else {
@fputs($fp, "HEAD $url HTTP/1.1\r\n");
@fputs($fp, "HOST: $host\r\n");
@fputs($fp, "Connection: close\r\n\r\n");
$headers = "";
while(!@feof($fp))$headers .= @fgets ($fp, 128);
}
@fclose ($fp);
$return = false;
$arr_headers = explode("\n", $headers);
foreach($arr_headers as $header) {
$s = "Content-Length: ";
if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) {
$return = trim(substr($header, strlen($s)));
break;
}
}
} else {
if ( file_exists($url) ) {
$return = intval(filesize((string)$url));
} else {
$return = 0;
}
}
$return = ($return > 0) ? round(($return / 1024), 0) : 0;
return $return;
};
function kanema_iod($src) {
require_once('phpQuery.php');
$doc = phpQuery::newDocumentXHTML($src);
phpQuery::selectDocument($doc);
foreach(pq('img') as $img)
pq($img)
->attr('size', remote_file_size( pq($img)->attr('src') ) );
return $doc->html();
}
function kanema_iod_footer() {
echo '';
}
add_filter('the_content','kanema_iod');
add_action( 'wp_footer', 'kanema_iod_footer' );
add_action( 'wp_header', 'kanema_iod_header' );