# LCP Hero Optimization

**MUST** · **ID:** `performance-lcp-hero-optimization` · **Category:** performance
**Source:** [Web Platform](https://web.dev/)
**Interactive version:** https://ui-guides-agent-rules.netlify.app/principles/performance-lcp-hero-optimization

> MUST: LCP images (hero, banner): Use `loading="eager"` + `fetchpriority="high"` + `decoding="async"`. Add `<link rel="preload" as="image">` in head. NEVER lazy-load above-the-fold content.

Preload above-the-fold images and prioritize LCP elements for fast perceived loading

Largest Contentful Paint (LCP) is a Core Web Vital measuring when the largest content becomes visible. Hero images are often the LCP element. Preloading and eager loading ensures they render as fast as possible.

## Bad — do not do this

`performance-lcp-hero-optimization-bad`

```tsx
export function LcpHeroOptimizationBad() {
  return (
    <div className="w-full max-w-md">
      <div className="bg-card border border-border rounded-lg overflow-hidden">
        {/* Lazy-loading hero image - delays LCP */}
        <img
          src="https://images.pexels.com/photos/1103970/pexels-photo-1103970.jpeg?auto=compress&cs=tinysrgb&w=800"
          alt="E-commerce store promotional hero showing colorful products"
          className="w-full h-48 object-cover"
          loading="lazy"
        />
        <div className="p-4">
          <h2 className="text-xl font-bold mb-2">Welcome to Our Store</h2>
          <p className="text-sm text-muted-foreground">
            Discover amazing products at great prices.
          </p>
        </div>
      </div>
      <div className="mt-4 p-3 bg-error/10 border border-error/30 rounded text-sm">
        <p className="font-medium text-error">Problems:</p>
        <ul className="text-xs text-error/80 mt-1 space-y-1 list-disc pl-4">
          <li><code>loading="lazy"</code> delays the hero image</li>
          <li>No <code>fetchpriority="high"</code> attribute</li>
          <li>No preload link in document head</li>
          <li>Browser discovers image late in rendering</li>
        </ul>
      </div>
    </div>
  );
}
```

## Good — do this

`performance-lcp-hero-optimization-good`

```tsx
export function LcpHeroOptimizationGood() {
  return (
    <div className="w-full max-w-md">
      {/* In real app, this would be in <head>:
          <link rel="preload" as="image" href="..." fetchpriority="high" /> */}
      <div className="bg-card border border-border rounded-lg overflow-hidden">
        {/* Eager loading with high priority for LCP element */}
        <img
          src="https://images.pexels.com/photos/1103970/pexels-photo-1103970.jpeg?auto=compress&cs=tinysrgb&w=800"
          alt="E-commerce store promotional hero showing colorful products"
          className="w-full h-48 object-cover"
          loading="eager"
          fetchPriority="high"
          decoding="async"
          width={800}
          height={400}
        />
        <div className="p-4">
          <h2 className="text-xl font-bold mb-2">Welcome to Our Store</h2>
          <p className="text-sm text-muted-foreground">
            Discover amazing products at great prices.
          </p>
        </div>
      </div>
      <div className="mt-4 p-3 bg-success/10 border border-success/30 rounded text-sm">
        <p className="font-medium text-success">Best Practices:</p>
        <ul className="text-xs text-success/80 mt-1 space-y-1 list-disc pl-4">
          <li><code>loading="eager"</code> loads immediately</li>
          <li><code>fetchpriority="high"</code> prioritizes the request</li>
          <li><code>decoding="async"</code> prevents render blocking</li>
          <li>Explicit dimensions prevent layout shift</li>
        </ul>
      </div>
    </div>
  );
}
```

## References

- [Optimize LCP](https://web.dev/articles/optimize-lcp)
- [Preload critical assets](https://web.dev/articles/preload-critical-assets)
