11ty / eleventy-img

Utility to perform build-time image transformations.
https://www.11ty.dev/docs/plugins/image/
433 stars 53 forks source link

Eleventy Transform: optimize `img`s' `srcset`s #222

Open olets opened 2 months ago

olets commented 2 months ago

Current

The eleventy-img Eleventy Transform transforms img srcs but not img srcsets.

Desired

The eleventy-img Eleventy Transform transforms img srcs and img srcsets.

Motivation

Currently, the transform can be used to reduce the reliance on external resources by saving remote srcs locally. If an img has a remote source in srcset, that source is not transformed and the browser may select the remote source. Optimizing srcset sources would make the Eleventy Transform a (Twig macro-friendly) drop-in solution for local-ifying images with remote sources.

Solution

To get the ball rolling, here's a possible approach to the normalization piece https://github.com/olets/eleventy-img/compare/main..transform-srcset

The optimization piece appears to be more complex. I skimmed the code, and paused. Could be down to make an attempt if given some pointers. But maybe that piece should be part of #215.