قبل بضعة أشهر، أطلق @Johaniمكون سمة ممتازًا لتحميل الصور بشكل كسول. وهذا يعني أن الصور تُحمّل فقط عندما تظهر في منطقة العرض أثناء التمرير، بدلًا من تحميلها فور ظهورها في أي مكان بالصفحة، حتى لو لم تكن مرئية للمستخدم بعد.
وهذا أمر رائع في المنتديات التي تحتوي المواضيع فيها على العديد من الصور، خاصة للمستخدمين الذين يملكون اتصالات ذات نطاق ترددي محدود.
إذا كنت تعرف بعض التفاصيل التقنية حول Discourse، فقد تتساءل: أليس Discourse يقوم بذلك بالفعل إلى حد ما؟ نعم، تستخدم التمرير اللانهائي وتُحمّل المنشورات وتُزال من الذاكرة أثناء تمرير المستخدم. هذا صحيح! لكننا نفعل ذلك عادةً على شكل «مجموعات»، وفي بعض لوحات الصور قد يحتوي منشور واحد على عشرات الصور الكبيرة. فلماذا تحميلها جميعًا دفعة واحدة بينما لم تكن مرئية بعد؟
في أحدث إصدارات Discourse، نقوم الآن بتحميل الصور الكبيرة بشكل كسول، ولا حاجة لمكونات أو إضافات إضافية. إذا قمت بالتمرير بسرعة كبيرة، فستلاحظ ظهور نسخة ضبابية منخفضة الدقة من الصورة الكبيرة كعنصر نائب. سيبدو الأمر شيئًا مثل هذا:
التفاصيل التقنية: نقوم بتوليد صورة صغيرة جدًا بحجم 10×10 بكسل وتحتوي على 32 لونًا، ونخزّنها كـ URI بيانات داخل المنشور، ثم يقوم المتصفح بتوسيعها إلى الحجم الصحيح — وهذا ينتج عنه حجم يقارب 300 بايت.
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.
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.
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
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.
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?
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.
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:
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.