All skills
Skillintermediate

Frontend Excellence

Server Components run on the server and send rendered HTML to the client. They can directly access databases, filesystems, and internal APIs without exposing them to the browser.

Claude Code Knowledge Pack7/10/2026

Overview

Frontend Excellence

React Server Components

Server Components run on the server and send rendered HTML to the client. They can directly access databases, filesystems, and internal APIs without exposing them to the browser.

// app/products/page.tsx (Server Component by default)
async function ProductsPage() {
  const products = await db.query("SELECT * FROM products WHERE active = true");
  return (
    <main>
      <h1>Products</h1>
      
        
    </main>
  );
}

Rules:

  • Server Components cannot use useState, useEffect, or browser APIs
  • Mark interactive components with 'use client' at the top of the file
  • Pass serializable props from Server to Client Components (no functions, no classes)
  • Keep 'use client' boundary as deep in the tree as possible

Streaming SSR


  return (
    <div>
        
      }>
          
      
      }>
          
      
    </div>
  );
}

Each Suspense boundary streams independently. Place boundaries around data-fetching components to avoid blocking the entire page.

Code Splitting


const HeavyEditor = dynamic(() => import('@/components/Editor'), {
  loading: () => ,
  ssr: false,
});

const AdminPanel = dynamic(() => import('@/components/AdminPanel'));

Split on:

  • Route boundaries (automatic in Next.js App Router)
  • Conditionally rendered components (modals, drawers, admin panels)
  • Heavy libraries (chart libraries, rich text editors, maps)
  • Below-the-fold content

Bundle Optimization

// next.config.js
module.exports = {
  experimental: {
    optimizePackageImports: ['lucide-react', '@heroicons/react', 'lodash-es'],
  },
};

Checklist:

  • Run npx next build and review the output size per route
  • Use @next/bundle-analyzer to identify large dependencies
  • Replace moment with date-fns or dayjs (save ~200KB)
  • Import specific functions: import { debounce } from 'lodash-es/debounce'
  • Prefer CSS over JS for animations (no runtime cost)
  • Tree-shake icon libraries: import { Search } from 'lucide-react'

Core Web Vitals Targets

MetricGoodNeeds WorkPoor
LCP (Largest Contentful Paint)<2.5s2.5-4.0s>4.0s
INP (Interaction to Next Paint)<200ms200-500ms>500ms
CLS (Cumulative Layout Shift)<0.10.1-0.25>0.25

LCP Optimization

  • Preload hero images: <link rel="preload" as="image" href="..." />
  • Use priority prop on above-the-fold `` components
  • Inline critical CSS, defer non-critical stylesheets
  • Avoid client-side rendering for above-the-fold content
  • Set explicit width/height on images to prevent layout shifts

Image Optimization

  • Use next/image or equivalent (automatic WebP/AVIF, responsive srcset)
  • Set sizes attribute to avoid downloading oversized images
  • Use placeholder="blur" with a base64 data URL for perceived performance
  • Lazy load below-the-fold images (default behavior)

Font Loading Strategy

// app/layout.tsx

const inter = Inter({
  subsets: ['latin'],
  display: 'swap',       // show fallback font immediately
  preload: true,
  variable: '--font-inter',
});

  return (
    <html className={inter.variable}>
      <body>{children}</body>
    </html>
  );
}
  • Use next/font for zero-CLS font loading with automatic subsetting
  • Set display: 'swap' to avoid invisible text during load
  • Self-host fonts instead of loading from Google CDN (saves DNS lookup)
  • Limit to 2 font families maximum

CLS Prevention

  • Always set width and height on images and videos
  • Use aspect-ratio CSS for responsive media containers
  • Reserve space for dynamic content (ads, embeds) with min-height
  • Avoid inserting content above existing content after load
  • Use CSS contain: layout for components that change size

Performance Monitoring


onCLS(console.log);
onINP(console.log);
onLCP(console.log);

Measure real user metrics (RUM), not just lab scores. Vercel Analytics and Google Search Console provide field data.