Jump to content
MediaWiki

Manual talk:$wgNativeImageLazyLoading

Add topic
From mediawiki.org
Latest comment: 9 months ago by Tunglinwu in topic it's not working
This page used the Structured Discussions extension to give structured discussions. It has since been converted to wikitext, so the content and history here are only an approximation of what was actually displayed at the time these comments were made.

Disable lazy loading for first iamge

[edit ]
Latest comment: 1 year ago 5 comments3 people in discussion

Is there a way of disabling lazy loading for content above the fold or at least for the first image? Non lazy loading content "above the fold" can actually improve largest contentful paint times in many instances. InnerCitadel (talk) 09:56, 12 April 2022 (UTC) Reply

I agree with previous comment = lazy loading of images should not apply to "above the fold" images. Or at least there should be a way to tell that some images should not be lazy loaded, like a list of image classes or other ...
Is this something that is being considered? Or has been discussed at some point? LMischler (talk) 12:38, 28 September 2022 (UTC) Reply
I agree and reported this at phab:T320762. Sophivorus (talk) 20:04, 13 October 2022 (UTC) Reply
For what's worth, here's a bit of code you can add to your LocalSettings.php to lazy-load all but the first image of every page:
$wgThumbCount = 0;
$wgHooks['ThumbnailBeforeProduceHTML'][] = function ( ThumbnailImage $thumbnail, array &$attribs, array &$linkAttribs ) {
	global $wgThumbCount;
	if ( $wgThumbCount > 0 ) {
		$attribs['loading'] = 'lazy';
	}
	$wgThumbCount++;
};
It can be trivially modified to lazy-load the first two images, or whatever. Hope it helps! Sophivorus (talk) 22:58, 14 September 2023 (UTC) Reply
Apparently it's not so simple, gallery thumbnails and plain images are processed before image thumbnails, so in order to lazy-load everything but the first image thumbnail, the code would be:
$wgThumbCount = 0;
$wgHooks['ThumbnailBeforeProduceHTML'][] = function ( ThumbnailImage $thumbnail, array &$attribs, array &$linkAttribs ) {
	global $wgThumbCount;
	$class = $attribs['class'] ?? '';
	if ( strpos( $class, 'thumbimage' ) !== false ) {
		$wgThumbCount++;
		if ( $wgThumbCount === 1 ) {
			return;
		}
	}
	$attribs['loading'] = 'lazy';
};
Again, this idea can be easily customized. Sophivorus (talk) 23:22, 14 September 2023 (UTC) Reply

it's not working

[edit ]
Latest comment: 9 months ago 1 comment1 person in discussion

I add $wgNativeImageLazyLoading = true; in LocalSettings.php.

But it still load all images. Tunglinwu (talk) 20:16, 7 July 2024 (UTC) Reply

AltStyle によって変換されたページ (->オリジナル) /