How Much Can a Service Worker Cache Shrink LCP in Core Web Vitals?
When a Service Worker serves HTML, CSS, and images from Cache Storage for a PWA or offline support, LCP (Largest Contentful Paint) drops sharply on second and later visits. In my test environment, a page with every file fetched from the server had an LCP of 1,164ms. When the HTML was also served from the Service Worker cache, the LCP was 124ms. However, when only CSS and images came from the cache and the HTML was fetched from the server every time, the LCP was 412ms, almost the same as the HTTP cache (408ms).
The test environment was Ubuntu 24.04, Node.js 22, Chromium 157 (headless) from Playwright 1.63.0, and web-vitals 6.2.3. The viewport was 412px wide and 823px high at a DPR of 1.75, and I slowed the page's CPU by 4x. Instead of a slow network, the server at localhost:8080 waits 300ms before sending any response and then sends the body slowly, at 200KB per second (about 1.6Mbps). LCP was measured with the attribution build of onLCP from web-vitals. Each value is the median of 7 runs on second and later visits. I did not test the LCP of the first visit (the visit that installs the Service Worker), real smartphones, real networks, real user data (field data), or browsers other than Chrome.
The Test Page and Service Worker
The page has a heading, a full-width image (824×464, a 110KB JPEG), and a short paragraph. On every page, the LCP element was the image (html>body>img).
<link rel="stylesheet" href="style.css">
...
<h1>猫の手日記</h1>
<img src="hero.jpg" width="824" height="464" alt="">
<p>きょうは朝から雨でした。窓の外を見ながら、猫と一緒にのんびり過ごしています。</p>
<script>navigator.serviceWorker.register('sw.js');</script>
The server sends Cache-Control: no-store on every file. Only the page used to compare against the HTTP cache had max-age=31536000 on the CSS and images.
The Service Worker that serves the HTML from the cache too is shown below. During installation, it stores the HTML (./), the CSS, and the image in Cache Storage. Later requests return the cached copy when one exists.
const CACHE = 'v1';
const FILES = ['./', 'style.css', 'hero.jpg'];
self.addEventListener('install', (event) => {
event.waitUntil(caches.open(CACHE).then((c) => c.addAll(FILES)).then(() => self.skipWaiting()));
});
self.addEventListener('activate', (event) => event.waitUntil(self.clients.claim()));
self.addEventListener('fetch', (event) => {
event.respondWith(caches.match(event.request).then((r) => r || fetch(event.request)));
});
The version that serves only CSS and images from the cache adds one line at the top of the fetch handler. For page navigations (requests for the HTML), it fetches from the server.
self.addEventListener('fetch', (event) => {
if (event.request.mode === 'navigate') return event.respondWith(fetch(event.request));
event.respondWith(caches.match(event.request).then((r) => r || fetch(event.request)));
});
For comparison, I also prepared a Service Worker that caches nothing and returns fetch(event.request) as is. The method was to open the page once in the same browser context to install the Service Worker (for the HTTP cache page, this is when the HTTP cache is filled), and then open it 7 more times in new tabs.
Results: Caching the HTML Brings LCP Down to 124ms
The chart below shows the median LCP of the 7 runs.

web-vitals splits LCP into four parts (following the breakdown in the web.dev guide to optimizing LCP). TTFB is the time until the first byte of the page arrives. Load delay is the time from TTFB until the image starts loading. Load duration is the time the image takes to download. Render delay is the time from when the image arrives until it is displayed. All values are medians of 7 runs in ms. The medians of the parts do not add up to the median LCP.
| Response method | LCP | TTFB | Load delay | Load duration | Render delay |
|---|---|---|---|---|---|
| No cache | 1,164 | 302.3 | 26.2 | 824.2 | 14.5 |
| HTTP cache only | 408 | 302.2 | 24.1 | 0.3 | 78.6 |
| Service Worker passing everything to the network | 1,168 | 304.4 | 23.6 | 827.0 | 12.7 |
| CSS and images only from the Service Worker cache | 412 | 304.0 | 27.0 | 1.1 | 78.7 |
| HTML also from the Service Worker cache | 124 | 2.1 | 28.8 | 1.4 | 89.5 |
Without a cache, most of the LCP was the image load (824ms) and TTFB (302ms). When CSS and images came from the cache, the image load dropped to 1.1ms, but the TTFB of about 300ms remained. The image cannot start loading until the HTML has been fetched from the server. When the HTML also came from the cache, TTFB was 2.1ms and LCP was 124ms. Most of the remaining time was render delay (89.5ms).
I also counted the requests that reached the server during the measurements. With the Service Worker that serves the HTML from the cache too, index.html, style.css, and hero.jpg each received 0 requests over the 7 visits. The deliveryType in Navigation Timing and Resource Timing was "cache-storage" for both the HTML and the image. (sw.js in the output is the number of requests for the Service Worker file.)
sw-cache median: LCP=124ms TTFB=2.1 loadDelay=28.8 loadDuration=1.4 renderDelay=89.5
sw-cache requests to server during 7 runs: index.html=0 sw.js=6 style.css=0 hero.jpg=0
With this approach of serving the HTML from the cache, users keep seeing the old HTML even after you change the HTML on the server. In my test, I changed the heading on the server from "Cat's Hand Diary (version 1)" to "Cat's Hand Diary (version 2)" after the first visit, then opened the page 3 more times. All 3 still showed "version 1". If you serve the HTML from the cache, you also need to decide how to replace the contents of Cache Storage when the HTML changes.
A Service Worker that only passes everything to the network had an LCP of 1,168ms, almost the same as the 1,164ms without a Service Worker. Installing a Service Worker alone does not reduce LCP. Which files it serves from the cache determines how much LCP drops.
Startup Time When the Service Worker Is Stopped
According to the web.dev article on navigation preload, after handling an event, a Service Worker stays running for a time the browser decides, and then it stops. If you open a page while the Service Worker is stopped, the request is delayed by the time it takes to start the Service Worker. That time varies with the device and the situation. In my test, I stopped the Service Worker with ServiceWorker.stopAllWorkers from the Chrome DevTools Protocol before each of 7 page opens.
| Response method | LCP | TTFB |
|---|---|---|
| HTML also from cache (running) | 124 | 2.1 |
| HTML also from cache (opened after stopping) | 104 | 9.7 |
| Static Routing API from cache (opened after stopping) | 124 | 3.0 |
When the Service Worker was stopped before opening the page, TTFB rose from 2.1ms to 9.7ms. However, the median LCP was 104ms, which was actually lower. The 7 LCP values ranged from 92 to 124ms, so the startup difference of about 8ms did not show up in the LCP values. I slowed only the page's CPU by 4x. I did not set any slowdown for the Service Worker.
According to the Static Routing API article, if you declare during installation with addRoutes() that a path should be served from Cache Storage, the browser can serve it from the cache without running the Service Worker. It is available from Chrome 123. In my test, I added the following to the Service Worker above. /sw-router/* is the path where I placed this page on the test server.
self.addEventListener('install', (event) => {
event.addRoutes({ condition: { urlPattern: { pathname: '/sw-router/*' } }, source: 'cache' });
});
Even when the page was opened with the Service Worker stopped, TTFB was 3.0ms. That is almost the same as when the Service Worker was running and handled the request in the fetch handler (2.1ms). workerStart in Navigation Timing for the HTML was 0 on all 7 visits. (When the Service Worker was stopped and the fetch handler served the response, it was 1.0 to 2.5ms.)
With a Stopped Service Worker, the HTML Request Still Reached the Server
When I opened the page with the Service Worker stopped, index.html still reached the server on all 7 visits, even though the response came from the cache. The HTML used by the page had deliveryType set to "cache-storage", so it came from Cache Storage.
sw-cache-cold median: LCP=104ms TTFB=9.7 loadDelay=23.3 loadDuration=1.1 renderDelay=69.4
sw-cache-cold requests to server during 7 runs: index.html=7 sw.js=6 style.css=0 hero.jpg=0
When I restarted Chromium with --disable-features=ServiceWorkerAutoPreload, this request count dropped to 0. The median LCP was 116ms, which was not much different from when the request reached the server.
sw-cache-cold median: LCP=116ms TTFB=10.3 loadDelay=21.1 loadDuration=1.7 renderDelay=73.9
sw-cache-cold requests to server during 7 runs: index.html=0 sw.js=6 style.css=0 hero.jpg=0
In Chromium 157, when a page is opened while the Service Worker is stopped, the request for the same HTML reaches the server even if the HTML is served from the cache. The count of requests reaching the server includes visits made while the Service Worker was stopped. When the Static Routing API served the response from Cache Storage, index.html received 0 requests even when the page was opened after the Service Worker was stopped.





