日本語

Fixing Lighthouse “Serves images with low resolution” Warning

​​Lighthouse​HTML,images

Lighthouse's "Serves images with low resolution" audit reports an image when its width and height in pixels are too small for the size it is displayed at. If you serve an image close to the displayed size multiplied by the screen's DPR (the number of device pixels per CSS pixel), the warning goes away. You will usually see this warning when featured images, thumbnails, logos, or icons on a blog look blurry on a high-density phone screen. With Lighthouse displayed in Japanese, the same audit appears under a Japanese title that means "Images are displayed at a low resolution."

On the page I tested, a 400px-wide image was displayed across the full width of the body text (380px on a phone), and this warning appeared. The best-practices score was 96. After I replaced the image with a 600px-wide one, the warning disappeared and the score became 100.

Note

The test environment was Ubuntu 24.04, Node.js 22, and Lighthouse 13.6.0 (the npm package). I used the Chrome for Testing 153 bundled with Playwright 1.63.0, and specified it with the CHROME_PATH environment variable. I ran Lighthouse from the command line and checked the Performance and Best Practices categories. I mainly used the default mobile settings, and some tests used --preset=desktop. The test pages were served from a server running in the test environment (localhost:8080). I did not test the Lighthouse panel in Chrome DevTools, PageSpeed Insights, the <picture> element, CSS background images, or results on a live public site.

The page that triggered the warning and the Lighthouse output

The page that triggered the warning is shown below. cat-400.jpg is 400px wide and 267px tall, and CSS width: 100% stretches it to the full width of the body text.

html
<style>
  body { margin: 0 auto; max-width: 640px; padding: 0 16px; font-family: sans-serif; }
  img { max-width: 100%; height: auto; }
</style>
<h1>猫の手日記</h1>
<img src="/cat-400.jpg" alt="水色の猫の顔" width="400" height="267" style="width:100%">
<p>画像の下に続く本文です。</p>

(The <head> and meta tags are omitted, and the code is reformatted for readability.)

I ran Lighthouse on this page. I used a small script (summarize.mjs) to pull the best-practices score and the result of this audit (its internal name in Lighthouse is image-size-responsive) from the JSON results.

console
$ npx lighthouse http://localhost:8080/before.html --only-categories=best-practices,performance --output=json --output=html --output-path=./out/before --chrome-flags="--headless=new --no-sandbox" --quiet
$ node summarize.mjs out/before.report.json
lighthouseVersion: 13.6.0  formFactor: mobile  DPR: 1.75  viewport: 412x823  locale: en-US
requestedUrl: http://localhost:8080/before.html
best-practices score: 96
image-size-responsive: score=0 title="Serves images with low resolution"
  <img src="/cat-400.jpg" alt="水色の猫の顔" width="400" height="267" style="width:100%"> | url=http://localhost:8080/cat-400.jpg | displayed=380 x 254 | actual=400 x 267 | expected=570 x 381

(In practice, I ran it from a small shell script that sets CHROME_PATH. Other lines of the output are omitted.)

In the HTML report, the Best Practices section lists the displayed size, the actual size of the image file, and the size Lighthouse considers appropriate (Expected size). When I ran with --locale=ja, the column names were shown in Japanese, meaning "displayed size," "actual size," and "expected size."

Lighthouse report with the Serves images with low resolution item expanded. In the row for cat-400.jpg, Displayed size is 380 × 254, Actual size is 400 × 267, and Expected size is 570 × 381.
Report before the fix

This audit has a weight of 1 and is pass/fail. On this page, this one audit failed, and the score dropped from 100 to 96.

Calculating the required size

Under Lighthouse's default mobile settings, the screen is 412px wide with a DPR of 1.75. To show a 380px-wide image sharply on a DPR 1.75 screen, you would ideally need an image about 665px wide.

However, the source code of this audit in Lighthouse 13.6.0 rounds the DPR down before it calculates the size, as shown in the table below. A comment in the code explains that on phones, DPR 3 and DPR 2 are hard to tell apart.

Screen DPR Value used in the calculation
2 or more 2
1.5 or more and less than 2 1.5
Less than 1.5 1

The Expected size is the displayed size multiplied by this value and rounded up. For a 380×254 display, multiplying by 1.5 gives 570×381.

The passing threshold is a bit lower. If the height or width of the displayed image is more than 64px, the image can be as small as 0.75 times the Expected size. For a 380×254 display, an image of at least 428×286 passes. The 400px-wide image did not reach this.

To confirm this threshold, I made two pages with square images displayed at width="300" height="300". The threshold is 338px, which is 300 × 1.5 × 0.75 rounded up.

console
best-practices score: 96
image-size-responsive: score=0 title="Serves images with low resolution"
  <img src="/sq-337.jpg" alt="水色の猫の顔" width="300" height="300"> | url=http://localhost:8080/sq-337.jpg | displayed=300 x 300 | actual=337 x 337 | expected=450 x 450

A 337×337 image failed, and a 338×338 image passed with a score of 100. The Expected size in the table says 450×450, but the warning goes away without going that large.

Icons have no 0.75x margin

For images whose height and width are both 64px or less, there is no 0.75x margin, so the image must be the full size calculated from the DPR. When I used a 48×48 PNG for an icon displayed at 48×48, the warning appeared.

console
image-size-responsive: score=0 title="Serves images with low resolution"
  <img class="icon" src="/icon-48.png" alt="猫のアイコン" width="48" height="48"> | url=http://localhost:8080/icon-48.png | displayed=48 x 48 | actual=48 x 48 | expected=72 x 72

Replacing it with a 72×72 PNG passed. Even when the displayed size and the file size are the same, a high-DPR screen needs more pixels.

The threshold is lower with the desktop preset

With --preset=desktop, the DPR is 1 and the screen is 1350px wide. The page with the 337×337 image, which had fallen below the 338px threshold on mobile, passed under the desktop settings. The page with the 400px-wide image still failed under the desktop settings, because it is displayed at 640×427, the full width of the body text.

console
lighthouseVersion: 13.6.0  formFactor: desktop  DPR: 1  viewport: 1350x940  locale: en-US
image-size-responsive: score=0 title="Serves images with low resolution"
  <img src="/cat-400.jpg" alt="水色の猫の顔" width="400" height="267" style="width:100%"> | url=http://localhost:8080/cat-400.jpg | displayed=640 x 427 | actual=400 x 267 | expected=640 x 427

When switching to a larger image, watch out for images that are too large

The simplest fix is to replace the image with a larger file. But if it is too large, the performance category shows "Improve image delivery." On the same page, I replaced cat-400.jpg with 800px-wide and 600px-wide images and checked the results.

Image Resolution warning Improve image delivery File size
400px wide Reported Not reported 12,180 bytes
600px wide Not reported Not reported 28,238 bytes
800px wide Not reported Reported 44,793 bytes

For the 800px image, the audit gave this reason:

console
image-delivery-insight: score=0 title="Improve image delivery"
  url=http://localhost:8080/cat-800.jpg wastedBytes=13843
    reason: This image file is larger than it needs to be (800x534) for its displayed dimensions (665x444). Use responsive images to reduce the image download size.

The 665×444 in the reason is the displayed size 380×254 multiplied by the DPR 1.75 (the height is 444.5, truncated to 444). The resolution warning appeared for the 400px image, which is below the 428px threshold (0.75 × 570px). The delivery warning appeared for the 800px image, and neither warning appeared for the 600px image.

Comparing how they look on a DPR 1.75 screen, the 400px image has blurry letter outlines.

A crop of the lower-left part of an image shown on a 412px-wide screen at DPR 1.75, with two versions stacked vertically. In the top image (400px wide), the caption text (which reads roughly "Then with a cat's paw") and the vertical lines are blurry. In the bottom image (600px wide), the text and lines are sharp.
400px-wide image (top) and 600px-wide image (bottom)

Using srcset to let the browser pick an image per screen

When the displayed width differs greatly between phones and desktops, one image may not fit both. In that case, prepare images of different widths and let the browser choose one with srcset and sizes on <img>. The web.dev guide on responsive images says that preparing around three to five sizes is a common approach.

html
<img src="/cat-400.jpg"
  srcset="/cat-400.jpg 400w, /cat-800.jpg 800w, /cat-1200.jpg 1200w"
  sizes="(max-width: 672px) calc(100vw - 32px), 640px"
  alt="水色の猫の顔" width="400" height="267" style="width:100%">

The values such as 400w are the widths of the image files in pixels. sizes describes the width at which the image is displayed. On this page, if the screen is 672px or less, the width is the screen width minus 32px of left and right margins; otherwise it is 640px. As explained in the MDN documentation for the img element, the browser uses the w values in srcset and the width from sizes to choose which image to load.

On this page, cat-800.jpg was loaded under both the mobile and desktop settings, and no resolution warning appeared. However, because the candidates I prepared were 400, 800, and 1200, "Improve image delivery" appeared under both settings. (Under the desktop settings, the reason was that 800×534 is larger than the displayed 640×427.)

Images specified with 1x and 2x are not checked by this audit

With srcset, you can also specify images by DPR, using values such as 1x and 2x, instead of widths such as 400w.

html
<img src="/cat-400.jpg" srcset="/cat-400.jpg 1x, /cat-800.jpg 2x"
  alt="水色の猫の顔" width="400" height="267">

On this page, cat-800.jpg was loaded at DPR 1.75, and no resolution warning appeared. ("Improve image delivery" appeared for the same reason as on the page with the 800px image.) However, in the source code I looked at earlier, images with 1x or 2x values in srcset are excluded from this audit. With this markup, the warning does not appear even when the image is too small.

Images that are not flagged

The same source code also excludes the following images:

  • CSS background images and SVG images
  • Images with object-fit set to something other than fill (such as cover or contain)
  • Images with CSS image-rendering set to pixelated or crisp-edges
  • Images that are not visible on screen when measured, and images displayed larger than the screen

In my tests, a 400px-wide image displayed with CSS image-rendering: pixelated, and a page where the image was placed below 2000px of empty space, both passed with a score of 100. In both cases, the loaded image was the same cat-400.jpg as before the fix.

Point

Even if this audit passes, not all images on the page are necessarily sufficient. For images lower on the page, or images with 1x or 2x in srcset, calculate the required size yourself from the displayed width and DPR, and check it against the actual file size.

​Posted by 86