Page MenuHomePhabricator

Replace PCS lazy-loading logic with standard "loading=lazy" attribute
Closed, ResolvedPublic

Description

We have some fairly heavy and sophisticated code and transformations in PCS to enable lazy-loading of images, when in fact the HTML standard has had a simple loading="lazy" attribute for some time now, which is supported in the latest WebViews of both Android and iOS platforms.

In the Android case, the System WebView is updated pretty aggressively and automatically (for obvious security reasons), so the vast majority of Android users will have the latest Chromium-based WebView (109).

In the iOS case, it looks like global usage of WebViews older than 15.4 accounts for ~2% of users.[1] Perhaps @Tsevener can fill in any other risks here, but it seems at first glance like there aren't other major road blocks.

[1] https://caniuse.com/loading-lazy-attr

Related Objects

StatusSubtypeAssignedTask
ResolvedDbrant
ResolvedMSantos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedMSantos
ResolvedMSantos
ResolvedJgiannelos
OpenNone
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
Resolvedhnowlan
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedWRai-WMF
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedTsevener
ResolvedJgiannelos
OpenBUG REPORTNone
ResolvedMSantos
ResolvedJgiannelos
OpenNone
ResolvedMSantos
ResolvedTK-999
DuplicateNone
Resolvedabi_
DuplicateNone
Resolvedabi_
OpenNone
OpenNone
OpenNone
InvalidNone
ResolvedJgiannelos
OpenNone
InvalidJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
Resolvedcooltey
ResolvedSNowick_WMF
ResolvedSNowick_WMF
ResolvedEevans
ResolvedJgiannelos
Resolvedhnowlan
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos
ResolvedJgiannelos

Event Timeline

Change 886932 had a related patch set uploaded (by Dbrant; author: Dbrant):

[mediawiki/services/mobileapps@master] [WIP] Remove lazy-loading logic and replace with loading=lazy attribute.

https://gerrit.wikimedia.org/r/886932

This ticket looks related: https://phabricator.wikimedia.org/T325623
I would prefer to have a more systematic approach like the one in the WIP patch from @Dbrant rather than manually improving lazy loading.
@Tsevener is this something we can do in iOS too?

@Jgiannelos Agreed. I would need to do some testing to see how it acts once the patch is ready. It seems like Safari on iOS does support it by default, for iOS15+, if I'm reading https://caniuse.com/loading-lazy-attr correctly. We do support iOS14 as well, so we'll need pull some numbers on iOS14 usage and test to see if the degradation is acceptable for those users.

The best I could test is via different versions of Simulator. Here are some screenshots from Safari inspector. The steps I took for this are:

  1. Load Elizabeth II.
  2. Clear the session cache.
  3. Go to simulator settings, clear the Safari cache.
  4. In Safari on machine, connect a web debug session to simulator article view.
  5. Pull to refresh on article in simulator.

Pre-change, iOS 14:

Screenshot 2023-03-21 at 9.38.26 AM (1×1 px, 289 KB)

Post-change, iOS 14 (loading spinner was shown during the localhost call, ~2.5 seconds). Subsequent attempts were in the 1.5~2s range.

Screenshot 2023-03-21 at 9.30.29 AM (1×3 px, 982 KB)

iOS 15 & 16 had about the same performance post-change as iOS 14 pre-change:

Post-change, iOS 15:

Screenshot 2023-03-21 at 9.35.28 AM (923×1 px, 259 KB)

Post-change, iOS 16:

Screenshot 2023-03-21 at 9.41.34 AM (1×1 px, 289 KB)

Offline mode still works for me across all OSes. We can also guide iOS users to enabling lazy image loading in iOS Settings > Safari > Advanced > Experimental Features > Lazy image loading.

MSantos subscribed.

During the Apps Sync, we have talked about how minimal the impact will be so it's safe to move forward.

Change 886932 merged by jenkins-bot:

[mediawiki/services/mobileapps@master] Remove lazy-loading logic and replace with loading=lazy attribute.

https://gerrit.wikimedia.org/r/886932

No, this patch got eventually reverted because it caused an outage (mismatch between js/html version of pcs output)
https://gerrit.wikimedia.org/r/c/mediawiki/services/mobileapps/+/908961

No, this patch got eventually reverted because it caused an outage (mismatch between js/html version of pcs output)
https://gerrit.wikimedia.org/r/c/mediawiki/services/mobileapps/+/908961

So if i understand it correctly, if the transform is rolled out first, and then after some while the JS change is made again, this should be fixable right ?

No because the JS loaded doesn't necessarily apply to the right document because the page/mobile-html output might be older (due to pregeneration).
In order for this rollout to work we need to have a way to request a specific version of our JS assets that its not easy at the moment with pcs being served on RESTBase.
If that's not possible we need to force a new output pregeneration for each new response but this is going to need a lot of time.

I think that currently we are prioritizing moving PCS away from RESTBase and when this happens we will have more flexibility on how to serve versioned CSS/JS assets.

Change #1082528 had a related patch set uploaded (by Dbrant; author: Dbrant):

[mediawiki/services/mobileapps@master] [Super WIP] Update and modernize image lazy-loading, take 2.

https://gerrit.wikimedia.org/r/1082528

Dbrant changed the task status from Stalled to In Progress.Mar 17 2025, 1:08 PM

Change #1082528 merged by Cooltey:

[mediawiki/services/mobileapps@master] Update and modernize image lazy-loading, take 2.

https://gerrit.wikimedia.org/r/1082528