From: Gilles Dubuc Date: Wed, 21 Aug 2019 09:04:45 +0000 (+0200) Subject: Add support for native image lazy loading X-Git-Tag: 1.34.0-rc.0~636^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=3b7eecfc471ed09b9860e79460ca04e42d510fd3;p=lhc%2Fweb%2Fwiklou.git Add support for native image lazy loading Bug: T230897 Depends-On: I6c0b01fafe2c4498852e9c9b81151aba759dc5eb Change-Id: I0307563b8f433dab062effe4dbfd7d4a9bbb8764 --- 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