// === SERVER-SIDE LAZY LOADING (by NgocVietCNC Speed Optimizer) ===
function ngocviet_lazy_load_images($html) {
$count = 0;
$html = preg_replace_callback('/]*)>/i', function($m) use (&$count) {
$count++;
$attrs = $m[1];
// Skip first 3 images (above the fold - LCP)
if($count <= 3) return $m[0];
// Skip if already has loading attribute
if(stripos($attrs, 'loading=') !== false) return $m[0];
// Add loading=lazy and decoding=async
return '
';
}, $html);
return $html;
}
// Start output buffering for lazy loading
ob_start('ngocviet_lazy_load_images');
// === END LAZY LOADING ===