The Day We Chased a Perfect Core Web Vitals Score (And What It Actually Took)
There was a moment when everything looked fine. The page loaded. The content appeared. There were no obvious errors. From a functional standpoint, nothing was broken.


There was a moment when everything looked fine.
The page loaded. The content appeared. There were no obvious errors. From a functional standpoint, nothing was broken.
Then we opened the performance report.
The numbers told a different story.
Largest Contentful Paint was painfully slow. Layout shifts were happening after the page appeared stable. Mobile performance dropped far below acceptable thresholds. The experience felt “fine” to the eye, but objectively, it was not.
That moment marked the beginning of a deeper investigation into what performance actually means, especially in the context of Core Web Vitals.
Understanding Core Web Vitals Beyond Definitions
Core Web Vitals are often introduced as three metrics: LCP, CLS, and INP. However, treating them as isolated numbers tends to miss the real point.
They are not metrics about systems. They are metrics about perception.
Largest Contentful Paint measures how quickly the most important content becomes visible. It is not about when the page starts loading, but when it feels usable.
Cumulative Layout Shift measures visual stability. It reflects whether the interface behaves predictably or causes frustration through unexpected movement.
Interaction metrics reflect responsiveness. They reveal whether the interface reacts instantly or feels delayed.
When these metrics degrade, the experience degrades. Not in theory, but in how users actually perceive the system.
The Starting Point: A “Working” but Heavy Page
The initial version of the system was intentionally left unoptimized. Images were large. All content loaded at once. There was no prioritization of what mattered first.
Everything was technically correct, but strategically wrong.
The browser had no guidance. It treated all resources equally.
To understand what was happening during rendering, the following sequence helps illustrate the baseline flow.

The key issue here is not just that resources are loaded. It is that everything is loaded without priority.
Large images compete with critical content. Non-essential sections delay meaningful rendering. The browser is forced to guess what matters.
Step One: Controlling What Loads First
The first meaningful improvement came from a simple realization. Not everything needs to load immediately.
Content below the fold does not need to block rendering above the fold.
This led to the introduction of lazy loading, not just for images, but also for content sections.
The mechanism relies on observing when an element enters the viewport.
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
loadContent(entry.target);
observer.unobserve(entry.target);
}
});
}, {
rootMargin: '50px'
});
document.querySelectorAll('.lazy-section').forEach(el => {
observer.observe(el);
});What changed here is not just timing, but intent.
The browser is no longer guessing. It is being guided.
Only content that is about to become visible is loaded. Everything else waits.
This reduces unnecessary work during the critical rendering phase, directly improving LCP.
Step Two: Fixing Layout Instability
After lazy loading was introduced, another issue became more visible. Layout shifts were still happening.
The cause was subtle. Even though content was delayed, space was not reserved.
When elements finally loaded, they pushed other elements downward.
The solution was not complex, but it required discipline.
Every dynamic element needed a predictable size.
.image-placeholder {
width: 100%;
height: 300px;
background: #eee;
}By reserving space, the layout becomes stable even before content arrives.
The rendering flow now looks different.

The absence of layout recalculation is what eliminates CLS issues.
Step Three: Reducing the Weight of What Loads
Even with proper loading strategy, large assets can still slow down rendering significantly.
In the initial version, images were served at high resolution regardless of device. This created a classic performance problem known as overfetching , where the browser downloads more bytes than necessary.
The impact is not trivial. Larger assets increase network transfer time, delay rendering, and directly affect Largest Contentful Paint. On slower mobile networks, this effect becomes even more pronounced.
The improvement comes from making assets adaptive rather than static.
Instead of sending one large image to all devices, multiple versions are provided, and the browser selects the most appropriate one based on viewport size.
<! - Before →
<img src="hero-1600.jpg" />
<! - After (responsive & optimized) →
<img
src="hero-600.jpg"
srcset="hero-600.jpg 600w, hero-800.jpg 800w"
sizes="(max-width: 768px) 100vw, 800px"
/>This change shifts responsibility to the browser, allowing it to make intelligent decisions about which resource to load.
The selection process can be understood as follows.

What changes here is not just file size, but efficiency. The browser no longer downloads unnecessary data, which reduces latency and improves rendering speed.
This approach also aligns well with mobile-first optimization strategies, where bandwidth constraints are more critical.
In more advanced scenarios, this can be extended further using modern formats such as WebP or AVIF, along with server-side compression strategies. However, even basic responsive image techniques already provide a significant improvement in LCP and overall performance.
This step demonstrates that performance is not only about when things load, but also about how much is being loaded.
Step Four: Prioritizing Critical Resources
At this stage, performance improved, but further gains required prioritization.
Not all resources are equal. Some are critical to rendering, others are not.
The browser can be instructed using resource hints.
<link rel="preload" href="hero.jpg" as="image">
<link rel="preconnect" href="https://images.unsplash.com">
<link rel="dns-prefetch" href="//images.unsplash.com">Preloading ensures that critical assets are fetched early.
Preconnect reduces the cost of establishing connections.
This step is less visible in code, but highly impactful in timing.
Step Five: Moving Optimization to the Server
Client-side optimization has limits. At some point, improvements must happen before content even reaches the browser.
This is where server-side strategies come into play.
One of the most impactful techniques is streaming HTML.
Instead of sending the entire document at once, the server sends it in parts.
The head is sent first, followed by critical sections, then the rest.
func streamHTML(w http.ResponseWriter, r *http.Request) {
file, _ := os.Open("./static/index.html")
defer file.Close()
scanner := bufio.NewScanner(file)
writer := bufio.NewWriter(w)
for scanner.Scan() {
line := scanner.Text() + "\n"
writer.WriteString(line)
writer.Flush()
if strings.Contains(line, "</head>") {
break
}
}
for scanner.Scan() {
writer.WriteString(scanner.Text() + "\n")
writer.Flush()
}
}This changes the rendering sequence significantly.

The browser no longer waits for the full document. Rendering begins earlier, improving perceived performance.
Step Six: Compression and Minification
Even after optimizing structure and flow, payload size still matters.
Compression reduces the size of data sent over the network.
func gzipMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
next.ServeHTTP(w, r)
return
}
w.Header().Set("Content-Encoding", "gzip")
gz := gzip.NewWriter(w)
defer gz.Close()
grw := gzipResponseWriter{ResponseWriter: w, gz: gz}
next.ServeHTTP(grw, r)
})
}Minification removes unnecessary characters from CSS and JavaScript.
These optimizations do not change behavior, but they reduce transfer time.
What Actually Changed
At the beginning, the system was loading everything without strategy.
At the end, the system became intentional.
Content was prioritized. Layout was stabilized. Assets were optimized. Delivery was improved.
The transformation was not about one technique. It was about coordination across multiple layers.
Final Reflection
Performance optimization is often misunderstood as a set of tricks.
In reality, it is a process of understanding how browsers think, how networks behave, and how users perceive delays.
Core Web Vitals are not goals in isolation. They are signals that guide better design decisions.
The journey from a heavy page to a highly optimized one is less about tools and more about clarity.
Clarity about what matters first. Clarity about what can wait. Clarity about how systems deliver experience.
Reference Implementation
A complete working example of this optimization journey, including all stages from baseline to server-optimized, is available here:
https://github.com/dimaspandu/cwv-article-demo
References
- Google. (2020). Web Vitals. https://web.dev/vitals/
- Grigorik, I. (2013). High Performance Browser Networking. O’Reilly Media.
- Osmani, A. (2018). The Cost of JavaScript. Medium. https://medium.com/ ...
- Google. (n.d.). Optimize Largest Contentful Paint. https://web.dev/lcp/
- Google. (n.d.). Avoid large layout shifts. https://web.dev/cls/
- Fielding, R. T. (2000). Architectural Styles and the Design of Network-based Software Architectures. Doctoral dissertation, University of California, Irvine.


Discussion
Comments
Replying to