Fast. Simple. No meetings. No delays.
Home / Blog / Web Development / Fixing Core Web Vitals on a Custom-Built Website

Fixing Core Web Vitals on a Custom-Built Website

Diagnosing and fixing LCP, CLS and INP on a hand-built site: critical rendering path, images, fonts, JavaScript and server response.

Cover graphic for the article: Fixing Core Web Vitals on a Custom-Built Website

To fix Core Web Vitals on a custom website, start from field data to see which metric fails on which pages, then work through each one: speed up the server and hero image for LCP, reserve space for CLS, and break up long JavaScript tasks for INP. Add automated guards so the gains are not lost.

This guide is for hand-built sites and applications, where you control the templates and the build. If you run an online store and want the shop-specific angle, see Core Web Vitals for eCommerce sites. For a broader, less technical list, see the website performance checklist.

Get field data first, then fix Core Web Vitals

Core Web Vitals are Google's user-experience metrics: Largest Contentful Paint (LCP) for loading, Cumulative Layout Shift (CLS) for visual stability, and Interaction to Next Paint (INP) for responsiveness. At the time of writing, the "good" thresholds published on web.dev are roughly 2.5 seconds for LCP, 0.1 for CLS and 200 milliseconds for INP, assessed at the 75th percentile of real visits. Thresholds and metrics evolve, so confirm them on web.dev before you set targets.

Before changing code, collect real-user data:

  • The Core Web Vitals report in Google Search Console groups URLs by status and device.
  • PageSpeed Insights shows field data from the Chrome UX Report when your page has enough traffic, next to a lab test.
  • Your own measurement using the open-source web-vitals JavaScript library, sending results to your analytics or a small endpoint, gives you per-page and per-template detail that the public report cannot.

Why lab data differs from field data

Lab tools such as Lighthouse run one simulated load on fixed hardware and network. Real users have slower phones, cached and uncached visits, logged-in states, consent banners, different regions and long sessions. INP in particular needs real interactions, so lab runs cannot fully measure it. Use lab data to reproduce and debug, and field data to decide what matters and whether you succeeded.

Group your URLs by template (home, product or article, search, checkout) and fix the worst template first. One shared template usually explains many failing URLs.

Fix LCP: server and hero asset

LCP measures when the largest visible element, often a hero image or headline, finishes rendering. Work through its parts in order:

  1. Server response time. Slow HTML delays everything. Look at database queries, uncached rendering and cold starts; see MySQL query optimisation for PHP applications for the usual culprits. Cache full pages or fragments where content allows, and consider a CDN.
  2. Discover the hero early. If the image is set by CSS background or injected by JavaScript, the browser finds it late. Put it in the HTML as an img element, and consider fetchpriority="high" on it. Never lazy-load the hero.
  3. Size and format. Serve responsive sizes with srcset and sizes, and modern formats such as WebP or AVIF with a fallback if needed. A hero image much larger than its display size is the most common waste.
  4. Remove render blockers. Inline the small amount of CSS needed for above-the-fold content or keep stylesheets small, and defer scripts that are not needed for first paint.
  5. Connections. Use preconnect for critical third-party origins, and avoid redirect chains.

Fix CLS: reserve space

CLS adds up unexpected movement of visible content. The fix is almost always to reserve space before the content arrives.

  • Give every image and video width and height attributes, or a CSS aspect-ratio.
  • Reserve fixed-size slots for ads, embeds, cookie banners and promo bars. If a banner must appear, overlay it or place it where it does not push content.
  • Do not insert content above existing content after load, such as late-arriving notices.
  • Animate with transform and opacity rather than properties that change layout.
  • Use stable placeholders (skeletons with the final dimensions) for content loaded by JavaScript.

Fix INP: long tasks and handlers

INP looks at how long the page takes to visually respond after clicks, taps and key presses, across the whole visit. Delays usually come from the main thread being busy.

What is a long task?

A long task is any piece of main-thread work that runs for more than 50 milliseconds. While it runs, the browser cannot respond to input or paint. Find them in the Performance panel of browser developer tools, where they are flagged, or with the Long Tasks and Long Animation Frames APIs in field monitoring.

What to do about them:

  • Ship less JavaScript: remove unused code, split bundles by route, and defer non-critical features.
  • Break up heavy work and yield to the browser between chunks, using scheduler.yield() where supported or a setTimeout-based fallback.
  • Keep event handlers light. Do the visual update first, and defer analytics, logging and heavy calculations.
  • Avoid forced layout, such as reading layout properties in a loop after writing styles.
  • Move expensive computation to a web worker, and debounce handlers on input and scroll.
  • Keep the DOM size reasonable, since large DOMs make every update slower.

Fonts and third-party code

Web fonts affect both LCP and CLS. Self-host them, subset to the characters you use, use font-display: swap or optional, preload the one or two critical files, and tune fallback font metrics so text does not jump when the real font loads.

Third-party scripts (tag managers, chat widgets, A/B testing, ad code) often cause the worst INP and layout problems because you do not control them. Inventory every one, remove those nobody uses, load the rest after the main content, and test with and without them to see what each costs.

Regression guards in CI

Performance degrades quietly, one feature at a time. Make regressions visible:

  • Run Lighthouse CI or a similar tool on key templates in your pipeline and fail or warn when budgets are exceeded, with realistic limits for bundle size and image weight.
  • Add a bundle-size check to pull requests.
  • Keep real-user monitoring running, and alert when a metric worsens on a template after a release.
  • Include a performance item in the definition of done for new features, especially anything adding scripts or media.

Lab checks catch big problems early but remain noisy, so use them as guard rails and rely on field data for the final verdict.

Reporting wins

Report in field data, per template, over time. Record the baseline before you start, note the dates of changes, and compare the same device class and period. Field data updates gradually, so allow several weeks of traffic before declaring success. Share what changed and which metric moved, and avoid promising ranking or revenue effects: good vitals remove friction, but they are one signal among many.

Putting it together

Measure, pick the worst template, fix the one metric that fails there, and add a guard before moving on. If a hand-built site needs a hands-on performance review, see our software development overview or get in touch.

Frequently asked questions

Why does lab data differ from field data?

Lab tools run one simulated load on fixed hardware and network. Real visitors use slower phones, varied networks, cached and uncached visits, logged-in states and consent banners, and they interact over a whole session. Use lab runs to debug and field data to judge success, especially for INP.

What is a long task?

A long task is main-thread work that runs for more than 50 milliseconds, during which the browser cannot respond to input or paint. Browser developer tools flag them in the Performance panel. Reduce them by shipping less JavaScript, splitting heavy work into chunks, and deferring non-critical code.

How do I prevent regressions?

Combine budgets and checks in your pipeline, such as Lighthouse CI and bundle-size limits on pull requests, with real-user monitoring that alerts when a metric worsens after a release. Treat performance as part of the definition of done, especially for features that add scripts, fonts or media.

Related articles

Web Development Tel Aviv

Startup Landing Page Launch Checklist

Everything a startup landing page needs before launch: message, speed, forms, analytics, metadata, privacy text and tracking.

6 min read

🚀 Start Now