Lazy Loading Bilder

Vor ein paar Monaten hat @Johani eine hervorragende Theme-Komponente veröffentlicht, um Bilder per Lazy Loading zu laden. Das bedeutet, dass Bilder erst dann geladen werden, wenn sie durch Scrollen in den sichtbaren Bereich gelangen, anstatt sofort geladen zu werden, sobald sie irgendwo auf der Seite erscheinen – selbst wenn sie für den Nutzer noch nicht sichtbar sind.

Das ist besonders auf Foren mit Themen, die viele Bilder enthalten, eine großartige Funktion, insbesondere für Nutzer mit Verbindungen mit begrenzter Bandbreite.

Wenn du mit einigen der technischen Details von Discourse vertraut bist, fragst du dich vielleicht: Hey @eviltrout, macht Discourse das nicht schon irgendwie? Ihr nutzt unendliches Scrollen und Beiträge werden beim Scrollen des Nutzers in den Speicher geladen und wieder entladen. Ja, das stimmt! Aber wir tun dies meist in „Chunks", und auf einigen Bildforen kann ein einzelner Beitrag Dutzende großer Bilder enthalten. Warum sollte man sie alle auf einmal laden, wenn sie noch nicht sichtbar sind?

In den neuesten Builds von Discourse laden wir nun automatisch große Bilder per Lazy Loading – es sind keine zusätzlichen Komponenten oder Plugins erforderlich. Wenn du wirklich schnell scrollst, siehst du zunächst eine unscharfe, niedrig aufgelöste Version eines großen Bildes als Platzhalter. Das sieht dann ungefähr so aus:

image

Technische Details: Wir generieren ein sehr, sehr kleines 10x10-Bild mit 32 Farben und speichern es als Data-URI im Beitrag. Der Browser skaliert es dann auf die richtige Größe – das ergibt insgesamt etwa ~300 Byte.

Bald wird es durch das korrekte Bild ersetzt:

Wir werden die Funktion in den nächsten Wochen noch weiter verfeinern. Bitte gib uns Feedback und Hinweise, falls du welche hast!

50 „Gefällt mir“

Should improve page loading performance nicely, especially on slow connections. Thanks for this improvement!

8 „Gefällt mir“

Awesome!

This is why I love Discourse - you keep adding stuff I didn’t think we needed! :+1:t3:

11 „Gefällt mir“

One thing I’m looking into is applying this to non-lightboxed images, such as those included via oneboxing links.

One issue is it’s a little tricky to know when to apply the logic, since we don’t know the filesize of the destination image. Originally my plan was to append the filesize of images, but it turns out that is quite tricky since we don’t always have a downloaded copy of the image available.

I think I’ll have to come up with a magic width x height, maybe 300x300px or so, and if the image has dimensions larger than that it’ll be lazy loaded. We do have those dimensions available regardless of onebox or upload.

14 „Gefällt mir“

Web bloat I find this article to be a good one on the subject of slow connections, do bear in mind that it has a very minimalistic theme, so don’t judge it by it’s cover so to speak. It might not quite be applicable here, but it’s always good to keep in mind.

I sometimes wish there were ways with Web APIs to detect if someone is on a connection where they pay a lot for bandwidth or one that’s slow.

2 „Gefällt mir“

Probably fine, but to cover animated GIFs which are still quite common I would relax that to something like 200×200.

3 „Gefällt mir“

Yeah I am not sure what the downside will be of going all the way down to 50x50, as long as we do not hit emojis it should be good. Even at 50x50 we may still save 25x if you don’t end up looking at the image

5 „Gefällt mir“

I vote for 150×150 then, as we definitely want to steer clear of anything remotely emoji-like in size…

4 „Gefällt mir“

I mean, previously, image greater than 4MB isn’t loaded properly (using mobile to access)

-edit-

1 „Gefällt mir“

That is completely unrelated. Max allowed image size is controlled in site settings. We already lightbox and thumbnail all images that are posted above a certain size. This is about topics with dozens or hundreds of images in them, not the size of any single image.

7 „Gefällt mir“

I just want to say thank you for including this feature.

6 „Gefällt mir“

Here’s some improvements:

10 „Gefällt mir“

Man, I thought I was going crazy. This feature is great for low bandwidth, but now i’m seeing this lazy loading all over the place when I am scrolling our forum. I have so much bandwidth and I’m on a computer. Maybe there should be some sort of buffer around areas you can’t see that load right before you scroll to them? Maybe only for mobile?

1 „Gefällt mir“
9 „Gefällt mir“

It’s not just about your bandwidth, it’s about unnecessarily loading the server/CDN.

As @falco linked above, the trend is towards more just-in-time asset delivery.

Is there anyway that the admin can still play with CSS to modify the lazy loading behavior? The somewhat unintended consequence is that some users are now saying that pictures load on demand more slowly compared to before. I was wondering if its possible to modify the CSS such that instead of either loading all pictures in the next e.g. 20 posts (prior behavior) or pictures only in the current post (current behavior), that we do something in the middle, e.g. load pictures in the next e.g. 3-5 posts.

1 „Gefällt mir“

It’s done with Javascript right now. There is no way to adjust it currently, but we might consider it in the future based on feedback.

4 „Gefällt mir“

I’ve been having issues with lazy load more and more lately, I see this at least once a day. It is hard repro, but I’m curious if there is anything I can do to troubleshoot this when it happens? The only thing related in the logs is this:

Uncaught [object Object]
Url: https://community.naturephotographers.network/assets/ember_jquery-57d09ec67e9e407d9b0d42aa1fefd1a470c45310d953b07793a3ca8adc6ec599.js
Line: 1
Column: 267440
Window Location: https://community.naturephotographers.network/t/twin-cuties/12785

1 „Gefällt mir“

Do you have the same problem with themes and plugins disabled, have you tried in safe mode?

1 „Gefällt mir“

It is very hard to reproduce, I went into safe mode and had to browse through 30 or so topics before finally hitting one that didn’t work. No related errors in the logs this time. I’m trying to avoid the downtime of testing each plugin, that’s why I’m hoping there may be some hints elsewhere to determine what the culprit may be. Thanks Jeff.

3 „Gefällt mir“