Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
eleventy-img uses the sharp image processor to resize the images to the configured sizes. The configuration code is adapted from the eleventy-img documentation.
Each image is made available in 3 variants: 400px, 850px, 1200px. The
srcset
image attribute declares the variants and thesizes
attribute gives a hint about which one to download and display.Advantages
Quality comparison
The screenshots (in PNG format) below are of the desktop version of a blog post, where the images are are scaled down to the content width, which is 840px.
I left out the 400px wide image which would normally only be served on smaller screens.
850px wide, 124 kB
This is the "medium" quality that is served as a fallback to browsers without support for
srcset
andsizes
attributes. I originally planned this to be the highest quality version, but it looks really blurry on a Macbook Pro.1200px wide, 220 kB
This is the one I picked as a compromise between file size and perceived quality. It amounts to around 1.4x pixel density (1200px wide image downscaled to 840px). That makes the text in the sample image blurry, but reasonably readable on higher density displays. Also note that it's a photo and the text is not the most important part. Screenshots of user interfaces would usually be in the PNG format and those look good at this pixel density, even on a Macbook Pro.
1600px wide, 355 kB
This the same size as the original image, but processed with the default compression parameters. The ~2x density would be optimal, but I find the transfer size (355 kB) too large.
Original/1600px wide, 476 kB
The original image as served on the blog up until now.
WebP and AVIF
I considered adding those using as enhancements (using the
<picture>
element).WebP looked bad in my experiments.
AVIF is not supported out of the box yet. See lovell/sharp#2289
Lazy loading
I switched to native lazy loading because of conflict with the LazyImages plugin. The plugin only worked properly on individual blog post pages anyway. On the index page, where it would be most beneficial, it could not resolve the relative paths because of the pagination.
References