Closed tannerdolby closed 3 years ago
I've updated the README.md and CONTRIBUTING.md file to include better documentation on adding new images to the gallery. Let me know if it's still unclear and if not I will close this issue.
I believe JPEG is still mandatory as 15% of Web users still don't have WebP support: https://caniuse.com/webp
@nhoizey Thanks for the info. I still have the fallback <img>
using a JPEG as its src
so that should be sufficient right?
I removed the srcSet
and sizes
attributes for the <picture>
's fallback <img>
if the .webp
sources aren't supported by that users browser.
<picture>
<source type="image/webp" ...>
<img
src="{{ image.imageData.large.jpg }}"
alt="{{ image.imageData.alt }}"
</picture>
Using a <source>
tag to include the large, medium and small .webp
images and using a JPEG as the last resort inside the fallback <img>
src.
If the browser can't support .webp
, the photo-name-large.jpg
would be image on the page which doesn't perform with the same responsiveness (as it doesn't use a srcSet
or sizes
). This might need to be tested or revisited to update the fallback image's responsiveness if indeed the webp <source>
isn't supported.
If I include a srcSet
for the fallback image then the person using the template will have to create 3 resized JPEG and 3 resized webp formats (where currently it's just 4 images so a little less work converting).
I think 15 % is still a population large enough to justify srcset
with multiple JPEG widths.
At least, if you don't have this srcset
, you should use a smaller JPEG fallback, IMHO.
All of this would be easier if people didn't have to generate the multiple formats and widths themselves, of course. There are multiple solutions to automate this.
I made eleventy-plugin-images-responsiver
to generate the HTML code, but it doesn't automate image resizing and format transformation. I use it with Cloudinary, others use it with Netlify Large Media, and I plan to try (and document) at least Imgix, Image Engine and TwicPics. But it can also be used with local transformations, with sharp for example.
I think 15 % is still a population large enough to justify srcset with multiple JPEG widths.
Yes, I agree. I'm going to revert back the documentation and global data to include large/med/sm .jpg
formats to use <img srcSet="">
and support that 15% percent that might not be able to view the .webp images.
I would like to use sharp for local transformations of image format and resizing to get rid of making users generate multiple formats and widths themselves. The current setup of forcing users to generate multiple formats and widths needs to be automated.
I will have a look at eleventy-plugin-images-responsiver
and research a bit more local transformations with sharp. Thanks for the feedback!
You're welcome!
I believe JPEG is still mandatory as 15% of Web users still don't have WebP support: https://caniuse.com/webp
I've added srcSet
with JPEG image formats back to the fallback <img>
if WebP isn't supported. This will provide that 15% of users without access to .webp
a much better viewing experience with appropriately sized .jpg
images.
FIX: commit 8b4fd35
It was pointed out by @ljc-dev on twitter today that its a bit unclear on what sizes and formats the images need to be in before adding them to
_data/gallery.json
as an object.In total: 4 pictures
.webp
source (1024px).webp
source (640px).webp
source (320px).jpg
source (1024px) or just use the original pictureNote:
src
can be whatever size as the browser will most likely be able to support the.webp
sources. But use the 1024px large source for best results.I recommend including a
image-name-large.jpg
format as thesrc
for the fallback<img>
in case the.webp
sources cannot be used.Removes the following srcSet from the fallback
<img>
inside<picture
>. Applying this update tofeature.njk
andbase.njk
.Clear things up about usage:
/images/
folder..eleventy.js
and utilizesharpImages("/images/image-name.jpg")
/images/
folder:.webp
but the sharp package has many options (I think .avif is supported)/images/
if you create the resized images externally._data/gallery.json
and create a new object with the image metadata (This is the last step)Filename: _data/gallery.json
The image is now added to the site and you can view it by running
npm run build
andnpm run serve