Does a data URI Image Speed Up LCP in Core Web Vitals?
When I embedded the large hero image at the top of the page as a data URI (data:image/jpeg;base64,…) in the HTML, LCP (Largest Contentful Paint) on the first visit over a slow mobile connection dropped from 1,684ms to 1,152ms on the test page. This is because one image request was removed, and the round-trip wait for it disappeared. On the other hand, on the second visit, the embedded version was 500ms slower than the page that used an image file cached by the browser. I'm sharing the numbers I measured in my test environment as they are, to help decide whether to Base64-encode an image and put it in the HTML when PageSpeed Insights or Lighthouse reports a slow LCP.
The test environment was Ubuntu 24.04 and Node.js 22. The browser was Chrome for Testing 158, bundled with Playwright 1.63.0. I used web-vitals 6.2.3 to measure LCP, sharp 0.33.5 to export the images, and Lighthouse 13.6.0. The pages were served from a small server I ran in the test environment (localhost:8080, HTTP/1.1). The test image was a 1200×800 pattern drawn with ImageMagick, not a real photo. I did not test HTTP/2 or HTTP/3, a CDN, browsers other than Chrome, PageSpeed Insights, real user data (field data), or writing a data URI in CSS background-image.
- 1. Preparing a page with an image file and a page with a data URI
- 2. Measuring LCP with web-vitals
- 3. On the slow mobile connection, the first-load LCP dropped by about 0.5 seconds
- 4. Without HTML compression, the reduction was smaller
- 5. With a data URI, the heading and text also appeared only together with the image
- 6. On the second visit, the data URI version was 500ms slower
- 7. Lighthouse's "Improve image delivery" could not check the data URI image
- 8. Things to check before using a data URI
Preparing a page with an image file and a page with a data URI
I prepared two images, both 1200×800 JPEGs.
| Image | Size | Characters after Base64 encoding |
|---|---|---|
| Fine pattern (large image) | 95,969 bytes | 127,960 characters |
| Smooth pattern (small image) | 11,077 bytes | 14,772 characters |
After Base64 encoding, both were about 1.33 times the original size. MDN's Base64 explanation also states that Base64 output is roughly one-third larger than the original.
The page came in two versions: one loads the image as an external file, and the other embeds it as a data URI. Below the image, I placed a heading and a short sentence.
<!-- Load the image as an external file -->
<img src="/big.jpg" alt="検証用の大きな画像" width="1200" height="800">
<h1>猫の手日記</h1>
<p>大きな画像の下に、記事の本文が続きます。</p>
<!-- Embed as a data URI (Base64 part omitted) -->
<img src="data:image/jpeg;base64,/9j/2wBDAAQEBAQEBAUFBQUHBwYHBwoJCAgJCg8K…" alt="検証用の大きな画像" width="1200" height="800">
The HTML with the large image embedded was 128,449 bytes. With gzip on the server, it became 96,416 bytes, close to the size of the original JPEG. The HTML with the small image was 15,263 bytes, and with gzip it became 10,418 bytes. For these two images, the extra size from Base64 almost disappeared when the HTML was compressed for delivery.
Measuring LCP with web-vitals
For measurement, I used the attribution builds of onLCP and onFCP from Google's web-vitals library. I opened the pages in Playwright with a 412×823 viewport (device pixel ratio 1.75), created a new browser context for each run, and disabled the cache. I used three network and CPU conditions:
- Slow mobile connection: 562.5ms latency, 1,474.56Kbps download, CPU slowed 4×
- 10Mbps download: 40ms latency, CPU slowed 4×
- No throttling: connected directly to localhost in the test environment
The values for the slow mobile connection are those used when reproducing Lighthouse's mobile setting (Slow 4G) with the DevTools method. For the 10Mbps condition, I used the network values in Lighthouse's desktop preset (RTT 40ms, 10Mbps download). The desktop preset has no value for the DevTools method, so I used the 40ms RTT directly as the latency. I took both values from the constants Lighthouse uses.
On the slow mobile connection, the first-load LCP dropped by about 0.5 seconds
These are the medians of seven runs each, with the HTML served gzip-compressed.
| Condition | Image size | Image file | data URI |
|---|---|---|---|
| Slow mobile connection | Large image | 1,684ms | 1,152ms |
| Slow mobile connection | Small image | 1,232ms | 680ms |
| 10Mbps download | Large image | 208ms | 188ms |
| 10Mbps download | Small image | 136ms | 140ms |
On the slow mobile connection, LCP dropped by 532ms for the large image and 552ms for the small image. The reduction was almost the same regardless of image size. On the 10Mbps connection, the difference was within 20ms, which is inside the range of variation across the seven runs (up to 32ms). Even on localhost with no throttling, with HTML uncompressed, the values fell between 32 and 40ms and showed no difference.
The breakdown of LCP explains why it dropped. These are the results from the first run on the slow mobile connection.
$ node measure.cjs 7 slow,mid ext-big,inline-big,ext-small,inline-small gz/ > out-gz.txt
$ cat out-gz.txt
ext-big run1: LCP=1688ms FCP=660ms url=http://localhost:8080/big.jpg html.transferSize=680 ... | TTFB=566 loadDelay=27 loadDuration=1073 renderDelay=22
...
inline-big run1: LCP=1160ms FCP=1160ms url=data:image/jpeg;base64,… html.transferSize=96716 ... | TTFB=564 loadDelay=0 loadDuration=0 renderDelay=596
(Part of the output is omitted.)
On the image-file page, fetching the image (loadDuration) took 1,073ms. Sending 95,969 bytes at 1,474.56Kbps (calculated as 1,024 bits per second per Kbps) takes about 508ms. The remaining roughly 565ms is almost exactly the configured latency (562.5ms). For the small image, loadDuration was 622ms; subtracting the transfer time of about 59ms leaves about 563ms. Regardless of image size, each request waits for the latency. With a data URI, that request disappears entirely. The HTML became 96KB larger, which adds transfer time, but since the wait for one request (562.5ms) was removed, the net result was a reduction of about 0.5 seconds.
Under this condition, the wait for a single request was long and accounted for a large part of LCP. On the 10Mbps condition, latency is only 40ms, so removing one request saves very little time. You can estimate the effect by treating the time saved with a data URI as roughly "the wait for one request."
Data URI images did not appear in the list of Resource Timing entries (performance.getEntriesByType('resource')). The only entry in the list was the web-vitals script, which I loaded later for measurement. Because of this, in the web-vitals breakdown, loadDelay and loadDuration were 0, and all the time after TTFB, including the time until the HTML finished downloading, was counted as renderDelay (rendering delay for the element). In web-vitals' onLCP code, when there is no LCP image resource entry (lcpResourceEntry), the fetch start and end times are taken to be the same as TTFB. A long renderDelay for a data URI image does not necessarily mean that rendering is slow.
Without HTML compression, the reduction was smaller
These are the medians for the same page served without HTML compression.
| Condition | Image size | Image file | data URI (compressed) | data URI (uncompressed) |
|---|---|---|---|---|
| Slow mobile connection | Large image | 1,684ms | 1,152ms | 1,312ms |
| Slow mobile connection | Small image | 1,232ms | 680ms | 700ms |
For the large image, the uncompressed version was 160ms slower. The HTML transfer size grew from 96,716 bytes (compressed) to 128,749 bytes (uncompressed). Sending the extra 32,033 bytes at 1,474.56Kbps takes about 170ms, which closely matches the LCP difference. If you plan to use a data URI, first check whether your HTML is being delivered compressed with gzip or similar.
With a data URI, the heading and text also appeared only together with the image
With a data URI, LCP dropped, but FCP (First Contentful Paint, the time until anything is first displayed) got worse. These are the medians for the large-image page on the slow mobile connection (HTML compressed).
| Page | FCP | LCP |
|---|---|---|
| Image file | 648ms | 1,684ms |
| data URI | 1,152ms | 1,152ms |
On the image-file page, the heading and text below the image appeared first at 648ms, and the image came later. On the data URI page, FCP and LCP happened at the same moment, and the heading and text appeared together with the image.
I also measured the time when the HTML finished downloading (responseEnd in Navigation Timing), three runs each. On the image-file page, the HTML finished at 570–573ms, and FCP was at 656–672ms. On the data URI page, the HTML including the 96KB of image data finished at 1,078–1,080ms, and FCP (1,148–1,164ms) came after that.
I also measured a page that loads one external CSS file (15,427 bytes) in the head, in the same way.
| Condition | Page | FCP | LCP |
|---|---|---|---|
| Slow mobile connection | Image file | 1,376ms | 1,776ms |
| Slow mobile connection | data URI | 1,300ms | 1,300ms |
| 10Mbps download | Image file | 184ms | 216ms |
| 10Mbps download | data URI | 200ms | 200ms |
(Medians of five runs each.)
On the slow mobile connection, the image-file page's FCP was delayed to 1,376ms because it waited for the CSS to download. The data URI page was faster in both FCP and LCP. The CSS finished downloading at 1,317–1,325ms on the image-file page and at 1,237–1,245ms on the data URI page. On both pages, FCP came after the CSS finished downloading. On the 10Mbps connection, FCP was 16ms earlier on the image-file page, and LCP was 16ms earlier on the data URI page.
On the second visit, the data URI version was 500ms slower
An external image file, once it is in the browser cache, is not fetched again on the next visit. A data URI is part of the HTML, so the image data is sent every time the HTML is fetched. The web.dev article on improving LCP notes that embedding with a data URL is an option when the LCP resource is small, but lists as drawbacks that embedded resources cannot be cached and that, in some cases, the decoding adds to the rendering delay of the element.
So I set the image file to return Cache-Control: max-age=3600, kept no-store on the HTML, opened the same page twice in a row, and measured the second visit.

| Condition | Image file (cached) | data URI |
|---|---|---|
| Slow mobile connection | 612ms | 1,112ms |
| 10Mbps download | 92ms | 152ms |
(Medians of five runs each.)
On the slow mobile connection, the data URI version was 500ms slower. On the image-file page, the image's transfer size (transferSize) on the second visit was 0, meaning it was served from cache. The data URI page received the 96,716-byte HTML every time, and it barely dropped from 1,152ms on the first visit.
Lighthouse's "Improve image delivery" could not check the data URI image
I ran Lighthouse 13.6.0 with the default settings (mobile) three times each on the same large-image page (HTML compressed). The LCP values were:
| Page | LCP, run 1 | LCP, run 2 | LCP, run 3 |
|---|---|---|---|
| Image file | 1,201ms | 1,353ms | 1,352ms |
| data URI | 1,205ms | 1,206ms | 1,202ms |
By default, Lighthouse does not actually slow down the network; instead, it estimates loading over a slow connection by calculation (Lighthouse's throttling explanation). In these results, the image-file page was 1.2 or 1.4 seconds, and the data URI page was 1.2 seconds every time, so the difference was not as large as what web-vitals measured.
The bigger difference appeared in the "Improve image delivery" item. On the image-file page, the following finding appeared all three times:
$ npx lighthouse http://localhost:8080/gz/ext-big.html --only-categories=performance --output=json --output-path=out/ext-big-1.json --chrome-flags="--headless=new --no-sandbox" --quiet
$ node lhsum.cjs out/ext-big-1.json "ext-big run1"
ext-big run1: lighthouse 13.6.0 formFactor=mobile throttlingMethod=simulate score=100 LCP=1201ms (1.2 s) FCP=639ms
...
image-delivery-insight: score=0 displayValue="Est savings of 60 KiB" metricSavings={"FCP":0,"LCP":300}
(I actually ran the two pages three times each in a for loop. Part of the output is omitted.)
The reason given was "This image file is larger than it needs to be (1200×800) for its displayed dimensions (721×481)." On the data URI page, the same image was displayed at the same size, but this item passed (score=1), and the findings table was empty. The "LCP request discovery" item was also marked not applicable (notApplicable) on the data URI page.
The reason lies in the code Lighthouse uses. NetworkRequestsHandler.ts in the Chrome DevTools repository contains the comment "We currently do not want to include data URI requests." and skips requests whose URLs begin with data:. "Improve image delivery" finds images from this list of network requests, so data URI images cannot be checked.
With a data URI, the image findings in Lighthouse's "Improve image delivery" disappear. That does not mean the image became lighter. In this test as well, the 1200×800 image, which is too large for its displayed size (721×481), was still embedded in the HTML as is.
Things to check before using a data URI
From this test, I found the following:
- The time saved was roughly the wait for one request. On a connection with 40ms latency, the difference fell within the range of measurement variation.
- Without HTML compression, the reduction got smaller by the amount of extra data from Base64.
- On a page without a CSS file, the heading and text placed after the image also appeared only together with the image, which made FCP slower.
- On the second visit, the cached image file was faster.
Before using a data URI, first try making the image itself lighter: resize it to fit the displayed size, or convert it to AVIF or WebP to make it smaller. The same web.dev article lists these as ways to reduce the load time of the LCP resource. They do not slow down later visits. After that, try a data URI only for a small LCP image on a page where many visits are first-time visits. Then measure the actual first-visit and second-visit LCP with web-vitals or a similar tool to confirm; this makes it easier to judge the effect.





