Skip to content

From 68 to 99: Fixing Images, Fonts and a Loading Screen on a Fashion Store

I converted the images and fonts and tuned the hero photo, and LCP improved from 8 seconds to 5.6. Then I found the real problem, a loading screen hiding the finished page, and removing it took LCP to 1.8 seconds.

NevilleFrontend engineer
· 8 min readImproves LCP

Son of God (opens in a new tab) is a Christian lifestyle clothing brand, and its site does what a fashion site should: big editorial photos, a premium typeface, and very little text. That's also a recipe for a slow page. Photos are the heaviest thing most sites send, and brand fonts come as a family of files, one per weight and style.

On a mid-range phone on a slow 4G connection, the home page took 8 seconds to show its hero photo. Four changes to images and fonts brought that down to 5.6 seconds. Then the filmstrip showed something none of those changes could fix, and one more change brought it to 1.8 seconds.

Before8.06 s (poor)LCP · performance 68
After1.76 s (good)LCP · performance 99
Lighthouse, mobile, slow 4G and 4× CPU slowdown, median of three runs.
VersionPerformanceFCPLCPPage weight
Before681.78 s8.06 s1,148 KB
Images, fonts and hero fixed751.47 s5.60 s614 KB
Loading screen removed991.47 s1.76 s614 KB

Here's what changed, in order.

1. Fourteen font files before the first paint

The first thing the network panel showed was a wall of fonts. As soon as the HTML arrived, the browser started downloading 14 font files at once, before the CSS and before the hero photo:

  • 10 weights and styles of Neue Haas Grotesk Display, as .otf files of about 73 KB each.
  • 4 weights of Helvetica Now Text, as .ttf files of about 128 KB each.

That's about 1.25 MB of font files on disk, and 459 KB over the network after the server compressed them. Most of those weights don't appear on the home page at all.

There were two problems here: the files were in the wrong format, and the browser was told to fetch all of them up front.

Chrome DevTools Performance panel, Network track. Right after the HTML document, ten Neue Haas Grotesk Display and four Helvetica Now Text font requests start together, ahead of the CSS file, the logo and the hero image.
Before: the Network track in Chrome's Performance panel. The 14 font files (boxed in pink) start downloading right after the HTML, ahead of the CSS, the logo and the hero photo.

The format: OTF and TTF to WOFF2

OTF and TTF are desktop font formats. WOFF2 is the same font in a container made for the web, with compression built in.

FontBeforeAfter (WOFF2)
Neue Haas Grotesk, Roman72.9 KB (.otf)17.8 KB
Neue Haas Grotesk, Light73.2 KB (.otf)17.9 KB
Neue Haas Grotesk, Medium73.4 KB (.otf)18.1 KB
Neue Haas Grotesk, Bold73.6 KB (.otf)19.9 KB
Neue Haas Grotesk, Black73.5 KB (.otf)19.9 KB
Helvetica Now Text, Bold126.0 KB (.ttf)35.2 KB
Helvetica Now Text, Black125.0 KB (.ttf)35.3 KB

Each file is about a quarter of its old size. The italics I converted saved the same.

The preload: download what the page uses

The fonts are loaded with next/font/local. By default it adds a <link rel="preload"> for every file in the family, so the browser fetches all of them at high priority, whether the page uses that weight or not. Ten weights preloaded meant ten downloads competing with the hero photo for the same connection.

Turning preload off fixes that:

src/lib/fonts.ts
export const neueHaasGrotesk = localFont({
  src: [
    { path: "./NeueHaasGrotDisp-55Roman-Trial.woff2", weight: "400", style: "normal" },
    // ...the other weights
  ],
  variable: "--font-neue-haas",
  display: "swap",
  fallback: ["Helvetica Neue", "Helvetica", "Arial", "sans-serif"],
  preload: false,
});

Without a preload, the browser only requests a font once the CSS says some text on the page needs it. On the home page that's four files instead of fourteen, 88 KB instead of 459 KB, and they're requested after the logo and the hero photo instead of before them.

Chrome DevTools Performance panel, Network track, after the change. The CSS file, logo-white.avif and hero-champagne.avif start first. A few WOFF2 font files start later, once the CSS has loaded, alongside the JavaScript chunks.
After: the CSS, the logo and the hero photo start first. The WOFF2 fonts (boxed in pink) are requested only once the CSS has loaded, and only the weights the page uses.

Converting the photos from PNG to AVIF turned up the biggest single file on the page, and it wasn't a photo. It was the logo.

The light-theme logo was an 8100 × 4800 pixel PNG weighing 1.36 MB. The header shows it 108 pixels wide on desktop and 61 on phones, and the footer shows it 135 pixels wide at most.

ImageBeforeAfter (AVIF)
Logo (light theme)1,358 KB (PNG)67 KB
Logo (dark theme)86 KB (PNG)13 KB
Hero photo106 KB14 KB
Quarter-zip editorial 02149 KB (PNG)40 KB
Quarter-zip editorial 03126 KB (PNG)28 KB
Quarter-zip editorial 04132 KB (PNG)40 KB
Presence duo119 KB (PNG)26 KB
Presence hat94 KB (PNG)17 KB

That's about 2.1 MB of files down to 245 KB. Not all of them load on the home page; the ones that do went from 294 KB to 132 KB over the network. AVIF is a modern format that compresses photos far better than PNG, which was designed for lossless graphics, and every current browser supports it.

One surprise: the hero photo's file was called hero-champagne.png, but it was a JPEG. Browsers don't care about the extension; they read the file. So check what a file really is (file hero.png in a terminal tells you) before you assume where the savings will come from.

3. Why I had to convert the images by hand

If you use next/image, you'd expect it to convert and resize images for you, and normally it does. On this site it didn't, and finding out why was the most useful part of the work.

The product photos are hosted on Cloudinary, so the site uses a custom image loader that turns each request into a Cloudinary URL with the right width, quality and format:

src/lib/cloudinary-image-loader.ts
export default function cloudinaryImageLoader({ src, width, quality }) {
  if (!src.includes("res.cloudinary.com") || !src.includes("/upload/")) {
    return src; // local images: returned as they are
  }
  const transforms = ["f_auto", `q_${quality ?? "auto"}`, `w_${width}`].join(",");
  return src.replace("/upload/", `/upload/${transforms}/`);
}

A custom loaderFile replaces Next.js's image optimizer for every image on the site, not only the Cloudinary ones. For local files, this loader returns the path unchanged. So every image in /public was sent exactly as it sits on disk, at the same size for every screen, in its original format. The srcset listed several widths, but they all pointed to the same file.

That's why converting to AVIF by hand made such a difference here. It also means two things I'd assumed were working weren't:

  • quality={65} on local images does nothing. Quality is something the loader passes on; this one ignores it for local files. The files are as compressed as they were when exported.
  • sizes on local images does nothing either. There's only one file to choose from.

The longer-term fix is either to upload the editorial photos to Cloudinary too, so they get the same treatment as product photos, or to let the loader send local paths to Next.js's own optimizer.

4. Product images: tell the browser how wide the card is

The product photos do go through Cloudinary, so sizes matters for them. The product card said:

tsx
sizes="(max-width: 768px) 100vw, 33vw"

That tells the browser a card is a third of the screen wide on anything bigger than a tablet. On a 1920-pixel monitor that's 640 pixels, or 1280 on a 2× screen. But the grid sits in a container with a maximum width, and cards never get much wider than 300 pixels. The browser was downloading images four times wider than needed.

src/components/shop/product-card.tsxafter
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 33vw, 300px"

The extra breakpoint says: once the screen is wider than the container, the card stops growing. Cloudinary now gets asked for a width that matches what's on screen.

5. Get the hero photo moving first

The Largest Contentful Paint (LCP) element on the home page is the hero photo. LCP measures when the biggest thing in the first screen appears, so this photo is the one that sets the score. It needs to start downloading as early as possible:

src/components/home/hero.tsx
<Image
  src="/images/editorial/hero-champagne.avif"
  alt="Son of God editorial — model in SOG quarter-zip"
  fill
  sizes="100vw"
  loading="eager"
  fetchPriority="high"
  className="object-cover object-top"
/>
  • loading="eager" stops the browser from waiting to see whether the image is on screen.
  • fetchPriority="high" moves it to the front of the download queue, ahead of images further down the page.

With the fonts no longer preloaded, the hero now starts downloading almost as soon as the HTML arrives, right alongside the logo and the CSS.

What the waterfall shows

On the slow 4G connection, the difference in download order is plain:

Before: the HTML arrives at 0.68 s. All 14 fonts start downloading straight away, all at high priority, and the last one finishes at 5.4 s. The logo and the hero photo can't start until 1.76 s, and because they're sharing the connection with the fonts, the hero takes until 6.3 s to arrive.

After: the CSS, the logo and the hero photo all start at about 0.6 s. The hero, now a 14 KB AVIF, has fully arrived by 1.4 s. The fonts follow afterwards. The hero photo arrived almost five seconds sooner. LCP, though, only improved by about two and a half seconds, from 8.06 s to 5.60 s. The photo was on the phone by 1.4 s, and Lighthouse still didn't count it as painted until 5.6 s.

6. The loading screen that hid the finished page

Lighthouse splits LCP into parts. For the "after" version:

Part of LCPTime
Time to first byte0.56 s
Resource load delay0.04 s
Resource load duration0.79 s
Element render delay3.74 s

Element render delay is the time between the image arriving and it appearing on screen. Here, the photo sat in memory, fully downloaded, for almost four seconds. The filmstrip showed why: from the first paint until after five seconds, the screen showed nothing but "SON OF GOD · Loading".

The site's theme provider hid the whole page until React had started:

src/providers/theme-provider.tsxbefore
<div className={cn("transition-opacity duration-300", mounted ? "opacity-100" : "opacity-0")}>
  {children}
</div>
{showOverlay && <AppLoaderOverlay fadingOut={mounted} />}

mounted only becomes true after the JavaScript has downloaded, parsed and run. On a slow phone that's seconds. Until then, the server-rendered page, hero photo included, was there but invisible, with a full-screen loading overlay on top.

The overlay was there to avoid a flash of the wrong theme. But the site already has a small inline script in the <head> that sets the theme before the first paint, so the overlay wasn't protecting against anything. Removing the wrapper and the overlay:

src/providers/theme-provider.tsxafter
<ThemeContext.Provider value={{ theme, mounted, toggleTheme, setTheme }}>
  {children}
</ThemeContext.Provider>
Before5.60 s (poor)LCP · element render delay 3.74 s
After1.76 s (good)LCP · element render delay 0.34 s
Lighthouse, mobile, slow 4G, median of three runs.

The performance score went from 75 to 99. All the work on images and fonts made the photo arrive sooner, but the user couldn't see it until this change.

Takeaways

  • Before optimising downloads, check the filmstrip. If the content is downloaded but not on screen, the problem is rendering, not the network.
  • Never hide server-rendered content until hydration. It makes LCP wait for all your JavaScript.
  • Fonts are often the first thing a page downloads. Check how many files you preload, and whether the page uses them.
  • Use WOFF2 for web fonts. OTF and TTF are about four times bigger.
  • Use AVIF (or WebP) for photos, and resize images to the largest size they're shown at.
  • A custom image loader replaces the optimizer for every image. Check the URLs your images actually load.
  • Give your LCP image loading="eager" and fetchPriority="high", and make sure nothing else is competing with it at the start.

All of these changes are live. See how the store loads now at sogworld.com (opens in a new tab).

Written by Neville

Geologist turned frontend engineer from Cameroon, based in Ghana. Makes web and mobile apps faster and writes down how. More about me

Liked this? Get the next one.

One deep dive a month. No spam, unsubscribe in one click.