Greenheart / idg.tools

Inner Development Toolkit - Transformational Skills for Sustainable Development
https://idg.tools
GNU Affero General Public License v3.0
22 stars 33 forks source link

Optimize images to reduce bandwidth usage #156

Open Greenheart opened 1 year ago

Greenheart commented 1 year ago

With images already being the largest part of our bandwidth usage, it will be important to serve optimized images going forward.


Since we have all content locally, we could theoretically optimize all images as part of the content build process, and cache the results. We could then create a shared util to pre-populate the srcset, src and other attributes of all img tags used on the webpage. This would require some custom code but might be doable.

Greenheart commented 1 year ago

For now, this has been solved manually since there aren't that many images yet. Since source images have been kept, this will be possible to migrate to a long term solution in the future.

Image processing could be set up using the sharp library, and image metadata (such as available formats, height and width) exported as JSON in a build step. This could then be used to serve the images with the right dimensions.

We could also consider also keeping fallback images for browsers that don't support the WebP format for OG images, although they will hopefully soon migrate to support WebP and other modern formats. https://www.stevefenton.co.uk/blog/2022/10/webp-opengraph-images/