How We Reduced Page Load Time from 6s to 1.8s (Step-by-Step Breakdown)
A client's product page was taking 6 seconds to show its main content on a mid-range phone over 4G. Bounce rate was climbing, and the Lighthouse performance score sat in the 40s.
After two sprints of focused work, we brought it down to 1.8 seconds. No framework rewrite and no "just buy a bigger server." Just a series of small, measurable fixes.
This post breaks down exactly how we managed to reduce page load time, in the order we did it, with the code we changed. If your app feels slow and you don't know where to start, this is the checklist I wish we'd had on day one.
TL;DR Measured with Lighthouse mobile preset (simulated 4G, mid-tier device), median of 5 runs.
Step 0: Measure before you touch anything
Short answer: Pick one metric, measure it the same way every time, and find out what's actually blocking the page before changing any code. Most slow pages have two or three big problems, not fifty small ones.
We tracked Largest Contentful Paint (LCP) as our main "page load time" metric, because it's the moment users actually see the main content. Google recommends keeping LCP at 2.5 seconds or less (web.dev guide on optimizing LCP).
Tools we used:
- Lighthouse in Chrome DevTools for quick lab runs
- PageSpeed Insights for real-user (field) data
- Chrome DevTools → Performance panel to see what blocked the main thread
- webpack-bundle-analyzer to see what was inside our JS
# Lighthouse from the CLI, so every run uses the same settings
npx lighthouse https://example.com/product \
--preset=perf \
--form-factor=mobile \
--output=json --output-path=./before.json
The Performance panel told us the story quickly: a 1.4 MB hero image, ~900 KB of JavaScript parsed before first paint, render-blocking Google Fonts, and a chat widget loading on every page.
Step 1: Fix the hero image (6.0s → 4.3s)
Short answer: The LCP element was a huge PNG. Converting it to AVIF/WebP, serving the right size per screen, and telling the browser to fetch it first gave us the single biggest win.
The hero image was a 2400px PNG served to every device, including 390px-wide phones. And to make it worse, it was lazy-loaded.
Before:
<img src="/hero.png" loading="lazy" alt="Product hero" />
After:
<picture>
<source type="image/avif" srcset="/hero-640.avif 640w, /hero-1200.avif 1200w, /hero-2000.avif 2000w" sizes="100vw" />
<source type="image/webp" srcset="/hero-640.webp 640w, /hero-1200.webp 1200w, /hero-2000.webp 2000w" sizes="100vw" />
<img src="/hero-1200.jpg" width="1200" height="600" fetchpriority="high" alt="Product dashboard showing order analytics" />
</picture>
What changed:
- Never lazy-load the LCP image.
loading="lazy"delays the exact thing users are waiting for. fetchpriority="high"moves the image up the browser's download queue.widthandheightstop layout shift (bonus CLS fix).- AVIF cut the file from 1.4 MB to about 110 KB on mobile.
Step 2: Shrink the JavaScript bundle (4.3s → 3.1s)
Short answer: We were shipping code for every route on the first load. Splitting by route and replacing two heavy libraries cut the initial JS roughly in half and freed up the main thread.
Running the bundle analyzer showed three problems:
- Every route was in one main.js
- moment.js with all locales (we only needed date formatting)
- A full charting library imported on a page that only showed one chart, below the fold
npx webpack-bundle-analyzer dist/stats.json
Route-level code splitting with React.lazy:
import { lazy, Suspense } from "react";
const ProductPage = lazy(() => import("./pages/ProductPage"));
const Reports = lazy(() => import("./pages/Reports"));
export default function App() {
return (
<Suspense fallback={<PageSkeleton />}>
<Routes>
<Route path="/product/:id" element={<ProductPage />} />
<Route path="/reports" element={<Reports />} />
</Routes>
</Suspense>
);
}
Replacing moment.js with the built-in Intl API:
// Before
import moment from "moment";
moment(order.date).format("D MMM YYYY");
// After: zero bundle cost
new Intl.DateTimeFormat("en-GB", {
day: "numeric",
month: "short",
year: "numeric",
}).format(new Date(order.date));
Loading the chart only when it's needed:
const SalesChart = lazy(() => import("./SalesChart"));
Initial JS dropped from ~900 KB to ~420 KB (uncompressed), and long tasks on the main thread dropped noticeably.
Step 3: Stop fonts from blocking the render (3.1s → 2.7s)
Short answer: Google Fonts added extra DNS lookups and a render-blocking stylesheet. Self-hosting a subset of the font, preloading it and using font-display: swap removed the delay.
<link rel="preload" href="/fonts/inter-latin-400.woff2" as="font" type="font/woff2" crossorigin />
@font-face {
font-family: "Inter";
src: url("/fonts/inter-latin-400.woff2") format("woff2");
font-weight: 400;
font-display: swap;
unicode-range: U+0000-00FF; /* Latin only */
}
We also cut from five font weights to two. Nobody noticed the difference in the design, but the browser did.
Step 4: Defer third-party scripts (2.7s → 2.3s)
Short answer: Chat widgets, analytics and tag managers compete with your own code for the main thread. Load them after the page is usable, or only when the user actually needs them.
The live-chat widget alone pulled in ~300 KB of JS on every page. Most visitors never opened it.
// Load the chat widget only on first interaction
function loadChat() {
const s = document.createElement("script");
s.src = "https://chat-vendor.example/widget.js";
s.async = true;
document.body.appendChild(s);
}
["pointerdown", "keydown", "scroll"].forEach((evt) =>
window.addEventListener(evt, loadChat, { once: true, passive: true })
);
Analytics moved to defer, and we removed two tracking pixels that marketing confirmed were no longer in use. Worth asking. Old scripts pile up.
Step 5: Remove wasted re-renders (2.3s → 2.1s)
Short answer: The product page re-rendered its whole component tree on every filter change and price update. Fixing state placement and memoization reduced main-thread work during load.
The React Profiler showed the product grid rendering three times before the page settled. The cause: a context provider at the top of the tree that changed on every update, with a new object each time.
// Before: new object on every render -> every consumer re-renders
<CartContext.Provider value={{ items, addItem }}>
// After: stable value
const value = useMemo(() => ({ items, addItem }), [items, addItem]);
<CartContext.Provider value={value}>
We also moved filter state down into the component that used it instead of keeping it at the page level. If you're on a newer React setup, check whether you even need manual memoization anymore. I wrote about that here: Do You Still Need useMemo and useCallback After React Compiler?
Step 6: Cache aggressively and use a CDN (2.1s → 1.8s)
Short answer: Hashed static assets can be cached for a year. Serving them from a CDN with Brotli compression cut repeat-visit times and shaved time off the first visit too.
# Hashed assets (main.a1b2c3.js) never change -> cache for 1 year
location ~* \.(js|css|woff2|avif|webp)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
}
# HTML should always be revalidated
location / {
add_header Cache-Control "no-cache";
}
We also:
- Enabled Brotli compression on the CDN (smaller than gzip for JS and CSS)
- Added preconnect for the one API domain the page needed on load
- Cached the product API response at the edge for 60 seconds
<link rel="preconnect" href="https://api.example.com" crossorigin />
What didn't help much
Not everything we tried was worth it:
- Minifying HTML saved a few KB. Not noticeable.
- Switching image CDNs made almost no difference once the images were the right format and size.
- Prefetching every link increased bandwidth use without improving the first load.
Being honest about what didn't work saves you a few days.
Your checklist to reduce page load time
- [ ] Measure LCP the same way every time (same device preset, median of several runs)
- [ ] Find your LCP element and make sure it's not lazy-loaded
- [ ] Serve AVIF/WebP with srcset and set
fetchpriority="high"on the hero - [ ] Run a bundle analyzer and split by route
- [ ] Replace heavy libraries with native APIs where possible
- [ ] Self-host and preload fonts, use
font-display: swap - [ ] Load third-party widgets on interaction, not on page load
- [ ] Profile re-renders with React DevTools
- [ ] Cache hashed assets for a year, serve through a CDN with Brotli
Wrapping up
Going from 6s to 1.8s didn't come from one clever trick. It came from measuring first, fixing the biggest blocker, measuring again, and repeating. The hero image and the JS bundle gave us most of the gains. Everything after that was smaller, but it added up.
If you're working on a slow React or web app and want a second pair of eyes, our team at EncodeDots does this kind of work as part of our frontend development services.
What was the biggest performance win in your project? Drop it in the comments. I'd love to compare notes. 👇
Comments
No comments yet. Start the discussion.