Lazy load post images - #539
Open
ButteredCats wants to merge 2 commits into
Open
Conversation
|
Compiled and tested. Seems to work fine for me. It gets rid of the svg stuff for single images. For galleries, it's still the same (doesn't have the svg stuff to begin with). |
Sparronator9999
added a commit
to Sparronator9999/redlib
that referenced
this pull request
Aug 6, 2026
Lazy load post images
Sparronator9999
added a commit
to Sparronator9999/redlib
that referenced
this pull request
Aug 6, 2026
Lazy load post images
almighty-atlas
added a commit
to almighty-atlas/redlib
that referenced
this pull request
Sep 7, 2026
Upstream sized post images by wrapping them in an <svg> of fixed width and height, which reserves the box but loads eagerly: the <img loading="lazy"> inside it sits in a <desc> element and is never rendered. PR redlib-org#539 replaced that with a real <img loading="lazy">, which restored lazy loading but left the image with no intrinsic size at all. The result was that a feed image occupied zero height until it arrived. On a 25-post multireddit feed, nine images finishing their load grew the page from 7774 to 9580 pixels - roughly 200 pixels of displacement each, while the reader is scrolling through it. Passing the real pixel dimensions as width and height attributes gives the browser the aspect ratio up front and keeps loading="lazy", so neither property has to be traded for the other. height: auto is what makes the attributes describe a ratio rather than fix the used height. Reddit does not always report dimensions - for posts served straight from i.redd.it both values are zero - so the attributes are only emitted when both are known, and those posts behave exactly as before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
<image>items don't appear to be a real thing despite displaying the image, and they didn't supportloading="lazy"so this basically just sets post images to always use the normal<img>tag and get rid of all the svg stuff that wasn't doing anything.