-
-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eleventy Transform: optimize img srcset directly (not indirectly) #222
Comments
img
s' srcset
simg src
and img srcset
and source srcset
Eleventy performs image optimization from So, it isn’t quite accurate to say that we don’t optimize |
(If you first read this comment in email, ignore that and read fresh here. Sorry about that. This was my first dev work after returning from a vacation, and it took many edits before my brain fully woke up!)
That's also an interesting feature idea, but not the one for my use case.
Not for all configurations, and for this request I'm interested in the cases where input To clarify my request: I'd like the transform to parse Say, for example, the input <!-- src/my-page.html -->
<img
alt="My cool image"
src="https://my-cool-cdn.com/1.jpg"
srcset="https://my-cool-cdn.com/1.jpg, https://my-cool-cdn.com/1.jpg&dpr=2 2x, https://my-cool-cdn.com/1.jpg&dpr=3 3x"
> Currently, adding the transform // eleventy.config.js
export default function (eleventyConfig) {
eleventyConfig.addPlugin(eleventyImageTransformPlugin);
} fetches the <!-- dist/my-page.html -->
<img
alt="My cool image"
src="/hashed-a.jpg"
srcset="https://my-cool-cdn.com/1.jpg, https://my-cool-cdn.com/1.jpg&dpr=2 2x, https://my-cool-cdn.com/1.jpg&dpr=3 3x"
> My desired behavior would result in this entirely local <!-- dist/my-page.html -->
<img
alt="My cool image"
src="/hashed-a.jpeg"
srcset="/hashed-a.jpeg, /hashed-b.jpeg 2x, /hashed-c.jpeg 3x"
> |
img src
and img srcset
and source srcset
Renamed yours back and created #266 for mine |
Current
The eleventy-img Eleventy Transform transforms
img
src
s but notimg
srcset
s.Desired
The eleventy-img Eleventy Transform transforms
img
src
s andimg
srcset
s.Motivation
Currently, the transform can be used to reduce the reliance on external resources by saving remote
src
s locally. If animg
has a remote source insrcset
, that source is not transformed and the browser may select the remote source. Optimizingsrcset
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.
The text was updated successfully, but these errors were encountered: