Even better images in Astro #597
Replies: 4 comments 5 replies
-
I'm new to the idea of 2x, 4x as sizes. Is there a benefit to them if you already have, say, |
Beta Was this translation helpful? Give feedback.
-
Is there a benefit to using an I've used the In general for both If nothing else, I'd want to make sure this specific use case for |
Beta Was this translation helpful? Give feedback.
-
Really agree with the improvements here. I would also like to stress that a new "version" of images in Astro should be adapter agnostic. So it should work in all runtimes, regardless if it is Node or V8 based. So we would need to make sure that everything we design, is supported by all these runtimes and potential tooling needs. Question would all the suggested ideas work in these Environments, e.g. with jSquash? |
Beta Was this translation helpful? Give feedback.
-
I was looking at adding AVIF support for our images today, but I think we have to stick with WebP for now. The native It would be great if there's a way to specify quality options per format instead. |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
Astro's
<Image />
component implements many must-have optimizations already. However, there is one thing it does not to at the moment: Auto optimizing for high and low DPR screens to achieve a better image quality and higher efficiency (less downloaded kB), where this proposal comes in handy.Background & Motivation
After reading the blog post Better images, I thought: Why not go a step further than automatically converting to WebP, by converting images to different qualities and dimensions automatically.
By crafting a specific
<img>
sizes
andsrcset
attribute, we can make sure:By adding this further step of automatic conversion, we can achieve images that weight less on smaller screens, vary images based on the DPR of the screen and at the same time keep sharp images on devices that need them. No server needed, a build step is enough for this (perfect for Astro).
Goals
px
, as innovated by Jake Archibald<img>
" technique as described my my blog postExample
Taken from the mentioned Astro blog post, the very first example. I could imagine it to look like this:
Config
mdx
autoDPR
attribute would be the toggle to enable the automatic conversionoutput
As the file names show, for each image, we'd have to generate 4 other images. This can extend processing time for a lot of images, so being selective with
autoDPR
makes sense here (e.g. the savings for a 15x15 image are probably not worth the increase in HTML output).Each image quality can be configured with the options above, where after the hash of the file (here
XXXXXX
), follow the dimensions, the DPR target and the quality of the image. Of course, this could also be factored into the hash to make it more compact.Really looking forward to your feedback!
Beta Was this translation helpful? Give feedback.
All reactions