Skip to content
Snippets Groups Projects

#3167034 "Leverage the 'loading' html attribute to enable lazy-load by default for images"

Merged #3167034 "Leverage the 'loading' html attribute to enable lazy-load by default for images"

Files

+ 7
0
@@ -851,6 +851,13 @@ function template_preprocess_image(&$variables) {
$variables['attributes'][$key] = $variables[$key];
}
}
// Without dimensions specified, layout shifts can occur,
// which are more noticeable on pages that take some time to load.
// As a result, only mark images as lazy load that have dimensions.
if (isset($variables['width'], $variables['height']) && !isset($variables['attributes']['loading'])) {
$variables['attributes']['loading'] = 'lazy';
}
}
/**
Loading