日本語

Reducing LCP in Core Web Vitals with fetchpriority on Images

​​Core Web Vitals​Chrome,HTML,Lighthouse,web-vitals

When the large image at the top of a page (the hero image) is the LCP (Largest Contentful Paint) element in Core Web Vitals, adding fetchpriority="high" to its <img> makes the browser start fetching the image sooner. On the page I tested, the median LCP measured by Lighthouse dropped from 5,243ms to 4,431ms. This is the fix for the "fetchpriority=high should be applied" line that appears under "LCP request discovery" in a Lighthouse report. I ran Lighthouse and web-vitals in a test environment and include the output and numbers from before and after the fix as they were.

Note

The test environment was Ubuntu 24.04, Node.js 22, Lighthouse 13.6.0, and web-vitals 6.2.3. For the browser I used Chrome for Testing 153, which comes with Playwright 1.63.0. The test page was served from a small server I ran in the test environment (localhost:8080, HTTP/1.1). Lighthouse ran with mobile settings and with network and CPU throttling. I did not test HTTP/2 or HTTP/3 servers, browsers other than Chrome, PageSpeed Insights, real user data (field data), or results on a live site.

The test page: other images come before the hero image

For the test I used a page like this. The <head> loads a CSS file and three scripts (about 80KB each). Near the top of the body is a header with four small category images, followed by a large image, hero.jpg (about 130KB), and below that four more article images. The largest image visible on screen is hero.jpg, and it was the LCP element.

html
<head>
<!-- Omit meta and title -->
<link rel="stylesheet" href="/style.css">
<script src="/app-a.js"></script>
<script src="/app-b.js"></script>
<script src="/app-c.js"></script>
</head>
<body>
<header>
  <img src="/thumb1.jpg" alt="カテゴリーの画像 1" width="600" height="400">
  <!-- Same for thumb2 to thumb4 -->
</header>
<h1>猫の手日記</h1>
<img src="/hero.jpg" alt="水色のもようの大きな画像" width="1200" height="675">
<p>大きな画像の下に、ほかの記事の画像が並びます。</p>
<div class="grid">
  <img src="/thumb5.jpg" alt="記事の画像 5" width="600" height="400">
  <!-- Same for thumb6 to thumb8 -->
</div>
</body>

Lighthouse reports a problem under "LCP request discovery"

I ran Lighthouse on this page. --throttling-method=devtools is the setting that actually slows the network and CPU while loading the page (the reason is explained in a later section). From the JSON output, I used a small script (summarize.mjs) to pull out the LCP, the "LCP request discovery" items, and the start and end times (in milliseconds) of each image request.

console
$ npx lighthouse http://localhost:8080/before.html --throttling-method=devtools --only-categories=performance --output=json --output-path=out/before-devtools-1.json --chrome-flags="--headless=new --no-sandbox" --quiet
lighthouseVersion: 13.6.0 throttlingMethod: devtools
performance score: 72
LCP: 5275 ms (5.3 s, score 0.22)
lcp-discovery-insight: score=0 title="LCP request discovery"
  [NG] fetchpriority=high should be applied
  [ok] Request is discoverable in initial document
  [ok] LCP resources shouldn’t use loading=lazy
  LCP element: <img src="/hero.jpg" alt="水色のもようの大きな画像" width="1200" height="675">
  /thumb1.jpg  start=  656 end= 2374
  /thumb2.jpg  start=  656 end= 2365
  /thumb3.jpg  start= 2368 end= 3470
  /thumb4.jpg  start= 2375 end= 3478
  /hero.jpg    start= 3077 end= 5250
  /thumb5.jpg  start= 3078 end= 4670
  /thumb6.jpg  start= 3078 end= 4678
  /thumb7.jpg  start= 3078 end= 4686
  /thumb8.jpg  start= 3096 end= 4892

"LCP request discovery" checks three things about how the LCP image is requested. The first two passed: the image can be found in the initial HTML, and it does not have loading="lazy". Only "fetchpriority=high should be applied" failed. In the HTML report, this appears as an item with a red triangle under Insights. When I ran Lighthouse with --locale=ja, the item name and the failing line were shown in Japanese (the Japanese text for "LCP request discovery" and for "fetchpriority=high should be applied").

Lighthouse report with the LCP request discovery item expanded. A red triangle marks the item, the line "fetchpriority=high should be applied" has a red prohibited sign, and the other two lines have green checkmarks. Below them is the img tag of the LCP image
Report before the fix (run with default settings). Only the fetchpriority=high line fails

Looking at the request times, the browser started fetching hero.jpg at 3,077ms, which is 2.4 seconds after thumb1.jpg and thumb2.jpg started (656ms). Only those two images started first. hero.jpg waited along with the images that came after it.

The fix: add fetchpriority="high" to the LCP image

The only change was one added attribute on the <img> for hero.jpg. Nothing else changed.

html
<img src="/hero.jpg" alt="水色のもようの大きな画像" width="1200" height="675" fetchpriority="high">

According to MDN's reference for the fetchpriority attribute, fetchpriority lets the developer give the browser a hint about the fetch priority it would otherwise choose on its own. The values are high (higher than others), low (lower than others), and auto (no preference, the default). MDN also notes that how the browser decides priorities, and how much this attribute changes them, depends on the browser.

When I ran Lighthouse again, all three checks under "LCP request discovery" passed.

console
$ npx lighthouse http://localhost:8080/after.html --throttling-method=devtools --only-categories=performance --output=json --output-path=out/after-devtools-1.json --chrome-flags="--headless=new --no-sandbox" --quiet
lighthouseVersion: 13.6.0 throttlingMethod: devtools
performance score: 75
LCP: 4405 ms (4.4 s, score 0.39)
lcp-discovery-insight: score=1 title="LCP request discovery"
  [ok] fetchpriority=high applied
  [ok] Request is discoverable in initial document
  [ok] LCP resources shouldn’t use loading=lazy
  LCP element: <img src="/hero.jpg" alt="水色のもようの大きな画像" width="1200" height="675" fetchpriority="high">
  /thumb1.jpg  start=  637 end= 2467
  /thumb2.jpg  start=  637 end= 2442
  /thumb3.jpg  start= 2443 end= 3928
  /thumb4.jpg  start= 2469 end= 3944
  /hero.jpg    start=  637 end= 4389
  /thumb5.jpg  start= 3503 end= 4937
  /thumb6.jpg  start= 3504 end= 4946
  /thumb7.jpg  start= 3504 end= 4954
  /thumb8.jpg  start= 3537 end= 5073
Lighthouse report with the LCP request discovery item expanded. A green circle marks the item, and all three lines, including "fetchpriority=high applied", have green checkmarks
Report after the fix (run with default settings). All three checks pass

LCP before and after: five runs each

To see how much the numbers vary, I ran Lighthouse five times on the page before and after the fix.

Run 1 Run 2 Run 3 Run 4 Run 5 Median
Before 5,275ms 5,243ms 5,240ms 5,253ms 5,225ms 5,243ms
After 4,405ms 4,431ms 4,494ms 4,425ms 4,470ms 4,431ms

The median LCP dropped by 812ms, and the performance score went from 72 to 75 (76 on the fourth run only).

Separately from Lighthouse, I also measured with onLCP from Google's web-vitals library. I opened the page with Playwright and set the network and CPU slowdown to the same values as Lighthouse's devtools setting (latency 562.5ms, download 1,474.56Kbps, CPU 4x slower). web-vitals is a library that measures Web Vitals metrics in real users' browsers, and its README says it reports values the same way Chrome does. The results were close to Lighthouse's.

console
$ node measure.cjs 5
...
before median: 5192ms (min 5188, max 5200)
...
after median: 4436ms (min 4136, max 4452)

The web.dev article on Core Web Vitals gives 2.5 seconds after the page starts loading as the target for a "good" LCP. In my measurements with a slow mobile connection, this page was still over 2.5 seconds after the fix. fetchpriority is one way to reduce LCP, and by itself it may not be enough to reach the target.

Why it got faster: hero.jpg starts fetching from the beginning

When I measured with web-vitals, I also recorded each image request's priority through the Chrome DevTools Protocol, both the initial value and any value it changed to.

console
before run1: LCP=5188ms element=hero.jpg
  /thumb1.jpg  initialPriority=Medium
  /thumb2.jpg  initialPriority=Medium
  /thumb3.jpg  initialPriority=Medium -> High
  /thumb4.jpg  initialPriority=Medium -> High
  /hero.jpg    initialPriority=Medium -> High
  /thumb5.jpg  initialPriority=Low -> High
  ...
after run1: LCP=4424ms element=hero.jpg
  /thumb1.jpg  initialPriority=Medium
  /thumb2.jpg  initialPriority=Medium
  /thumb3.jpg  initialPriority=Medium -> High
  /thumb4.jpg  initialPriority=Medium -> High
  /hero.jpg    initialPriority=High
  /thumb5.jpg  initialPriority=Low -> High
  ...

Before the fix, hero.jpg started at Medium and was raised to High later. After the fix, it starts at High. The final priority is High in both cases. The only difference in the recorded priorities is the initial value.

The following chart shows, from the first Lighthouse run, the time from start to end of each image request as a horizontal bar. Before the fix, the fetch for hero.jpg did not begin until about 3 seconds. After the fix, it begins at the same time as thumb1.jpg and thumb2.jpg.

Two horizontal bar charts stacked vertically. In the top chart, "before the fix", the hero.jpg bar starts around 3 seconds, and the LCP line is at 5.3 seconds. In the bottom chart, "after the fix", the hero.jpg bar starts around 0.6 seconds, and the LCP line is at 4.4 seconds
Start to end of each image request (first Lighthouse run)

The total time from start to end is longer after the fix (2,173ms before, 3,752ms after). As the chart shows, after the fix the other images load in parallel while hero.jpg is being fetched, and thumb1.jpg through thumb4.jpg finish loading earlier. The fetch takes longer, but it starts 2.4 seconds sooner, so the time when the fetch finishes moves from 5,250ms to 4,389ms, about 0.9 seconds earlier.

The web.dev article on optimizing LCP also notes that even when the LCP image can be found in the HTML, depending on how the browser sets priorities, its loading may not start at the same time as the first resources loaded on the page. The explanation is that images are not render-blocking resources, so the browser does not load them at the highest priority from the start.

With default Lighthouse settings, the LCP number did not drop

I also ran Lighthouse three times each before and after the fix using the default settings, without --throttling-method. The Lighthouse throttling documentation says this setting does not slow the network. Instead, it estimates how a slow connection would load the page from a record of a load that was not throttled. The documentation also says PageSpeed Insights uses this same setting.

console
before simulate run1: LCP: 4655 ms (4.7 s) performance score: 81
before simulate run2: LCP: 4585 ms (4.6 s) performance score: 82
before simulate run3: LCP: 4653 ms (4.7 s) performance score: 81
after simulate run1: LCP: 4954 ms (5.0 s) performance score: 80
after simulate run2: LCP: 4804 ms (4.8 s) performance score: 81
after simulate run3: LCP: 4955 ms (5.0 s) performance score: 80

With these settings, the LCP after the fix was 0.2 to 0.3 seconds longer. The "LCP request discovery" item behaved as it did with the devtools setting: it failed before the fix and passed after. On this test page, the default settings' LCP numbers did not show the effect of fetchpriority. The reduction appeared only with --throttling-method=devtools, which actually slows the network while loading the page, and with the web-vitals measurement. The Lighthouse documentation says the default setting is usually as accurate as the devtools setting or more so, but that it can sometimes estimate poorly. It also says the devtools setting cannot fully reproduce a slow network.

Use fetchpriority="high" on only one or two images

The web.dev article on optimizing LCP recommends adding fetchpriority="high" only to images that are likely to be the LCP element, and limiting it to one or two images based on common desktop and phone screen sizes. Adding it to many images removes its meaning as a priority signal. MDN also advises using it sparingly, because overusing it or setting priorities incorrectly can hurt performance.

The same article also covers fetchpriority="low". One example is an image that appears early in the HTML but is not visible at first, such as the second and later slides of a carousel. Setting low lowers its priority. The article also recommends checking the request priority in DevTools after making a change, and confirming the result with both lab data (such as Lighthouse) and field data (real user data).

​Posted by 86