-
Could the preview thumbnails not be a low res or scaled down version of the uncompressed image?
Would help in most cases.
But wouldn't help on that page as still too many far too large images were inlined.
What would help is a "only load images in view". But as you scrolled it would still blow the memory. Additionally this would break jumping to specific comments, as the height of comments above the one you jumped to isn't known and the act of jumping would start loading the images (and scroll the effective jumped to comment downwards as large things load above it).
There's no real solution that produces no edge cases, because it's always possible to inline a third party hosted image that is a 500MB jpg... there would be no way I could know, it would still blow things up.
If I tried to think about measures for things uploaded, then the best I would have is:
- Do not display thumbnails at all, just links to images.
- Reduce maximum file upload size from 30MB back down to 10MB.
- Detect on a per post basis the number of attachments inlined, and limit it to 1 (because there are 25 posts per page, so that still allows 25 images).
- Do not actually inline images... instead just put placeholders. Have JS on the page look at the sum of all placeholders and decide whether to load things (based on assumption of file size).
These things are all a bit crappy.
They prevent native mobile phone uploading of images (bike tag of bike would need post-processing to reduce image size).
They would prevent classifieds from just showing all of the images inline (lots more clicking to see what you're buying).
They would require JS for every page rather than supporting older devices (albeit with more RAM). Arguably login already does this, but I want to undo that and all JS-less browsing to function.
And it is an edge case... we have tens of thousands of classifieds threads with photos inlined, we have bike tag of bike, we have project threads... and this is the first time it has arisen.
That it's so rare an edge case and is going to be solved by time... the upgrade of devices with less RAM, the emergence of SOC CPUs with better RAM capabilities, etc... has me not feeling any urgency or priority to solve it.
It's a single page... it's viewable on desktops (assuming your computer is from the last 20 years)... and the impact to people browsing is very limited. Edge cases happen, but the only question is whether it's acceptable... for me it is, it's an edge case.
In the last 5 years the number of times that has been reported across almost 2B page views is once... that one page. That's well within my bounds of acceptable.
- Do not display thumbnails at all, just links to images.
-
Reduce maximum file upload size from 30MB back down to 10MB
Could you do this selectively for file types which render on load? There's no problem with a 30MB PDF or MP4, but hundreds of 5MB JPGs having to download and render every time you visit a page is a PITA even on devices which can handle it. Nobody needs to be attaching image files bigger than 4k resolution, they're just lazy and can't be arsed to do anything but fling camera files at your server🙂
Most files 30MB limit, images 3MB limit is more than enough.
-
You could use some FE javascript to detect screen width, and request a resized version of each image depending on screen size; you (currently) know that no image is going to be wider than about 762px so there would be some big savings to be had.
Probably not worth it because it would be a bit of work, and would come with inflated hosting costs, and as you say it's a pretty rare edge case. But it's a common strategy.
Edit: Just thought of another one. Just automatically downsize every uploaded image to have a max-width of 726px. Saves on hosting and bandwidth costs. Could store the originals in Glacier in case you ever want to change layout.
-
One simple change to image tags may fix it.
This didn't exist when you wrote the forum code, but it's well supported now.https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-loading
Depending on browser implementation this may also be clever enough not to load images you have skipped past (when jumping straight to a comment) unless you then scroll back up to those posts.
Could the preview thumbnails not be a low res or scaled down version of the uncompressed image? Or at least make that the case after say... 10mb is exceeded in attachments uploaded?