ILSA provides image handling for you:
- ILSA hosts images on a CDN and provides you with direct links to those.
- ILSA resizes images so we can serve a smaller image if the image is rendered smaller.
- ILSA uses WebP by default, but falls back to JPEG if we detect the browser doesn’t support WebP.
The goal is to provide the fastest user experience, mainly by reducing the transferred image sizes.
In the Backoffice you can configure which image sizes you want us to create. You can configure the width (in pixels) and we’ll automatically calculate the matching height to maintain the aspect ratio.
Add the fields images[].srcset
, images[].src
and images[].aspect_ratio
to your fieldset.
Render the images like this:
function renderImage(img, width) {
const el = document.createElement('img');
el.src = img.src; // Not used by modern browsers, but still required by the HTML5 spec.
el.srcset = img.srcset;
el.sizes = '20vw'; // Important! Set this to the percentage of the viewport this image will consume.
el.width = width;
el.height = width / img.aspect_ratio; // By precalculating the height there will be fewer jumps when rendering. Good for SEO (Largest Contentful Paint specifically), but not required.
}
IMPORTANT
It’s important to set the sizes
property on your <img>
-tag. Otherwise browsers will always download the largest image. Our srcset
s contain URLs with their width in pixels, but the browser needs to now how large you’re planning on rendering the image.
NOTE
If you set a width and height on the image the browser can allocate space for it earlier, resulting in fewer reflows and a faster Largest Contentful Paint.
If you’d like to have more control over the resized images rather than using on our srcset
, request the fields images[].variants[].url
, images[].variants[].width
and images[].variants[].height
.
WARNING
Per our stability guarantees, the URLs might change. URLs returned from the API are guaranteed to remain working for at least one hour (but in practice seldom change).