From 3b7eecfc471ed09b9860e79460ca04e42d510fd3 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Wed, 21 Aug 2019 11:04:45 +0200 Subject: [PATCH] Add support for native image lazy loading Bug: T230897 Depends-On: I6c0b01fafe2c4498852e9c9b81151aba759dc5eb Change-Id: I0307563b8f433dab062effe4dbfd7d4a9bbb8764 --- includes/DefaultSettings.php | 10 ++++++++++ includes/media/ThumbnailImage.php | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 98ffe71249..0b14e56ebb 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -9108,6 +9108,16 @@ $wgFeaturePolicyReportOnly = []; */ $wgSpecialSearchFormOptions = []; +/** + * Toggles native image lazy loading, via the "loading" attribute. + * + * @warning EXPERIMENTAL! + * + * @since 1.34 + * @var array + */ +$wgNativeImageLazyLoading = false; + /** * For really cool vim folding this needs to be at the end: * vim: foldmarker=@{,@} foldmethod=marker diff --git a/includes/media/ThumbnailImage.php b/includes/media/ThumbnailImage.php index 7ee6dcbee3..6e4412ca8f 100644 --- a/includes/media/ThumbnailImage.php +++ b/includes/media/ThumbnailImage.php @@ -110,7 +110,7 @@ class ThumbnailImage extends MediaTransformOutput { * @return string */ function toHtml( $options = [] ) { - global $wgPriorityHints, $wgPriorityHintsRatio, $wgElementTiming; + global $wgPriorityHints, $wgPriorityHintsRatio, $wgElementTiming, $wgNativeImageLazyLoading; if ( func_num_args() == 2 ) { throw new MWException( __METHOD__ . ' called in the old style' ); @@ -126,6 +126,10 @@ class ThumbnailImage extends MediaTransformOutput { 'decoding' => 'async', ]; + if ( $wgNativeImageLazyLoading ) { + $attribs['loading'] = 'lazy'; + } + $elementTimingName = 'thumbnail'; if ( $wgPriorityHints -- 2.20.1