Skip to content

This notebook belongs to

Sadat Jubayer

Senior Software Engineer at Premio

If found, please return to hello@jubayer.dev

Vol. 7Seven years of building

Started
January 2020
Everyday tools
TypeScript, Vue, React, Next.js, NestJS, React Native
Education
B.Sc. CSSE, AIUB, 2020
2 min readPerformance

Boost the LCP image with fetchpriority

Raise the fetch priority of your LCP image, lower eager offscreen images, and compare their initial priorities in Chrome DevTools.

Your venue page shows a wide photo of the main hall. Two photos in a carousel start fetching during the same load, even though they sit outside the first slide. If the hall photo is the Largest Contentful Paint (LCP) element, you can ask the browser to give its request more priority.

Put the hint on the image request

Before you edit the HTML, record a reload in Chrome's Performance panel and inspect the LCP marker. Use the element from that recording. On a narrower viewport, the title might take the place of the photo as the largest element. Check the viewport you want to improve.

For a page where the hall photo is the candidate, put the fetch priority hint on its img in the initial HTML. Give the eager carousel images low if they're out of view at first. The example shows the image markup before any carousel styling. Use your own image URLs and dimensions.

<figure>
  <img src="/images/hall.webp" alt="Concert hall"
       width="960" height="540" fetchpriority="high">
</figure>

<aside aria-label="Other venues">
  <img src="/images/studio.webp" alt="Rehearsal studio"
       width="480" height="270" fetchpriority="low">
  <img src="/images/stage.webp" alt="Outdoor stage"
       width="480" height="270" fetchpriority="low">
</aside>

In the request log you can compare the hall image's initial priority with those of the studio and stage images.

Use high for the image you confirmed in the trace. The browser uses the hint alongside its own rules, so the effect is a change in relative priority. The exact priority label can depend on the resource and how the browser discovered it. If you decide to lazy-load lower slides instead, leave their priority at the default unless you have a trace showing a reason to lower it.

Compare two cold loads

In Chrome's Network panel, turn on Disable cache and show the Priority column. Reload with the same viewport and network throttling, once with the hints and once with the attributes removed. Inspect initial and final priorities. Chrome can raise an image's priority after layout shows it in view, so the final label can hide a difference at request start.

Chromium can start the first large image requests at Medium. In the three-image example, the hints moved the hall to High and the other two to Low. Check the labels in your own trace.

Go back to the Performance panel for the LCP timing. A higher priority is useful if downloads compete and the image request spends time waiting. A request that starts late needs a different check. If you see a long gap before the request appears, look at how the browser discovers the LCP image before adjusting any more priorities.