yceffort
◆ SERIES 3 POSTS

Service Worker Caching Deep Dive

The third cache layer that did not fit in the caching chapter of Frontend Performance Optimization Deep Dive. From the general theory of proxies, lifecycles, and strategies to applying it to a Next.js blog and measuring it with GA4

README

The browser has three cache layers: the HTTP cache, the CDN cache, and the service worker cache. The first two got a full chapter in my book, but the last one was cut for length. This series pays off that debt.

It comes in three parts. Part 1 is the general theory: where a service worker sits in the request path and what lifecycle it lives through, what kind of storage Cache Storage is without a TTL, and what to base the choice among the five caching strategies on. Part 2 applies that theory to a real blog on the Next.js App Router. It goes through the traps set by soft navigation, prefetching, and next/image, and checks the change before and after deploying the service worker with real-user data from GA4. Part 3 measures the cost of going through the worker, which Part 2 left unresolved. After confirming why real-user data never produces a control group, it builds one directly with Playwright and a shaping proxy, and separates the shares of worker startup, navigation preload, and CPU speed.

Reading in order is recommended, but if you are already familiar with service workers, starting with the case study in Part 2 is fine.

03 ITEMS

All posts

in order
01

How Service Worker Caching Works: The Proxy, the Lifecycle, and Five Strategies

#service-worker#caching#browser
This post covers the service worker material that did not fit into the cache chapter of Frontend Performance Optimization Deep Dive (published in Korean). It works through why caches go stale, why the old version shows up after a deploy, what to store under which strategy, and whether you should use one at all, and measures a 104KB opaque response being counted as 6.6MB of storage.
Updated
24 min read
02

Applying Service Worker Caching: App Router Traps and GA4 Field Data

#service-worker#caching#nextjs
I made this blog (Next.js App Router) open offline. On the first deploy, the post I had just read would not open offline; on the second, posts opened but every image was broken. After fixing the problems from soft navigation, prefetching, and next/image one at a time, GA4 real-user data showed returning-visitor FCP 634ms faster on average and TTFB 525ms slower on average.
Updated
27 min read
03

Measuring the Cost of Going Through a Service Worker: Building in the Lab the Control Group GA4 Could Not Give Me

#service-worker#web-performance#caching
I set out to confirm the 500 ms that part 2 left as the cost of going through the worker, but the hard reloads that would form the control group arrive at under one a day. With a control group built from Playwright and a shaping proxy, going through the worker cost 2 ms on a navigation. Most of the extra time on a post click came from the worker saving the post HTML in the background over the same connection, and the gap between lab and field data was a measurement definition difference caused by 103 Early Hints.
Updated
50 min read