Working on a project with a team mate and trying to solve pagespeed insights issues, we ended up discussing how WordPress duplicates image files for each “add\_image\_size” you set.
This just means that every single image you upload gets duplicated for every size you define.
This causes terrible Uploads directory bloat with some sites being multi-gigabytes in size when in reality they have maybe 300mb of images and not all of them are even used in the actual frontend of the site.
Is there a good existing solution for this?
Can we get the WP team to perhaps improve this?
My recommendation would be as follows:
* WP has defaults, fine.
* Themes have add\_image\_size() , fine.
* WP should not generate duplicates until the frontend code loads an image url with size dimensions attached.
* For safety and to avoid abuse WP core would then match url dimension params \[define a format like &w=##&h=###\] that matches the default sizes and/or the themes added image sizes.
* If a match is found, generate the correctly sized image in the uploads folder still, but in a subdir like “cached\_images” or whatever they want to call it.
* Subsequent loads of the image url with size params would load from that cached directory instead of the uploads dir.
* This way it would only generate multiple-size duplicates as needed, based on the images’ actual usage on the frontend.
* This would reduce Media bloat, and when a site is copied/moved the cached directory can be ignored and it would automatically recreate and repopulate it based on actual site content.
​
Thoughts?
[ad_2]
https://github.com/syamilmj/Aqua-Resizer
Look into implementing this. You can ditch the entire add_image_size function so that WordPress stops generating those images, and you can resize them on the fly whenever you need them with Aqua Resizer. And if the image already exists at a certain size, it serves it up.