Priority images
Images are lazy-loaded by default: the browser only fetches them when they come close to the viewport. That is right for every image but the one visible at once, often the largest element of the page, which Largest Contentful Paint measures. Mark that one priority:
<twig:Picasso:Image src="hero-banner.jpg" width="1920" height="1080" sizes="100vw" priority="{{ true }}" alt="Hero banner" /><picture> <source type="image/avif" srcset="/image/glide/filesystem/kittens.jpg?w=16&h=9&fm=avif&q=75&fit=contain&s=9ca01d7dc5ea9bccbfa9262f966de958 16w, /image/glide/filesystem/kittens.jpg?w=32&h=18&fm=avif&q=75&fit=contain&s=062ed551951c74eb14d2e2dc4531dd94 32w, … 13 more …, /image/glide/filesystem/kittens.jpg?w=2400&h=1350&fm=avif&q=75&fit=contain&s=bfdeb5ae30c1db4ee2884e937eeeb3a7 2400w" sizes="100vw" /> <source type="image/webp" srcset="/image/glide/filesystem/kittens.jpg?w=16&h=9&fm=webp&q=75&fit=contain&s=b9d25089177194075c6b4ce0fd90b16e 16w, /image/glide/filesystem/kittens.jpg?w=32&h=18&fm=webp&q=75&fit=contain&s=ad7e17b0796014239b80b4e666aed729 32w, … 13 more …, /image/glide/filesystem/kittens.jpg?w=2400&h=1350&fm=webp&q=75&fit=contain&s=7d66846c1f9dc8b71ab1985639f93784 2400w" sizes="100vw" /> <img src="/image/glide/filesystem/kittens.jpg?w=1920&h=1080&fm=jpg&q=75&fit=contain&s=240330102f1ce5d1485d8f5f64c06026" srcset="/image/glide/filesystem/kittens.jpg?w=16&h=9&fm=jpg&q=75&fit=contain&s=51f372bc3cfcd511a08a08c63e330780 16w, /image/glide/filesystem/kittens.jpg?w=32&h=18&fm=jpg&q=75&fit=contain&s=d81d435f5591a7dded2c7e2dcde415d5 32w, … 13 more …, /image/glide/filesystem/kittens.jpg?w=2400&h=1350&fm=jpg&q=75&fit=contain&s=d4bc1540b03b76d893ee3870314cb0c2 2400w" sizes="100vw" width="1920" height="1080" loading="eager" fetchpriority="high" alt="Three tabby kittens" /></picture>loading="eager": fetched at once, not when scrolled to.fetchpriority="high": ahead of the other images and scripts of the page.- No placeholder, even with a default one: the image itself should be on screen as soon as possible.
Use it on one image per page, two at most: if everything is a priority, nothing is.
Preloading
Section titled “Preloading”With symfony/web-link installed, a priority image is also preloaded: the bundle adds a Link header to the response, so the browser starts fetching the image before it has parsed the HTML down to the <picture>.
composer require symfony/web-linkLink: </image/glide/filesystem/hero-banner.jpg?w=640&fm=avif&q=75&s=…>; rel="preload"; type="image/avif"; imagesrcset="/image/glide/filesystem/hero-banner.jpg?w=640&fm=avif&q=75&s=… 640w, …"; as="image"; fetchpriority="high"; imagesizes="100vw"- The link preloads the first
<source>of the<picture>, the format browsers pick first (AVIF by default), with itssrcsetandsizes: the browser preloads the very file the<picture>will use. Itstypelets browsers that cannot decode that format skip the preload. An image with a single format, orunoptimized, preloads the<img>itself. - The header can be sent before the page as 103 Early Hints, when your server supports them.
- The link is added to the main request, so a priority image rendered in a fragment (
render(), ESI) or cached HTML is not preloaded: preload it yourself there, with thepreload()Twig function ofsymfony/web-link.
Turn it off with the preload option.
To fine-tune instead, set loading and fetchPriority yourself:
{# Visible at once, but not the main element #}<twig:Picasso:Image src="logo.png" width="200" height="80" loading="eager" alt="Logo" />