101
LVL 04 — SENIOR-IN-TRAININGSESSION 101DAY 101

NEXT.JS SSR

🎫 PIXELCRAFT-087
Feature | 🔴 Expert | Priority: 🟠 High

PixelCraft's public gallery needs SEO. Currently it's a client-rendered SPA — search engines see a blank page. Migrate the gallery to Next.js with server-side rendering. Build a marketing landing page. Google can finally index us.
CONCEPTS.UNLOCKED
🔍
Why SSR
Search engines need HTML, not empty <div id="root">. A client-rendered SPA sends blank HTML + JavaScript. Google can execute JS but it's slow and unreliable. SSR sends pre-rendered HTML — instant indexing, instant previews.
Next.js
React framework with SSR, SSG, API routes, file-based routing. The industry standard for production React. Used by Netflix, TikTok, Notion. React is the engine; Next.js is the car.
🖥️
Server vs Client Components
Server Components run on the server, send HTML. Client Components run in the browser, handle interactivity. Default is server. Add 'use client' when you need useState, onClick, browser APIs.
📄
SSG (Static Site Generation)
Pre-render pages at build time. The landing page never changes → generate HTML once, serve as a static file. Fastest possible: no server, no database, just HTML from a CDN.
🔄
ISR (Incremental Static Regen)
Static pages that re-generate periodically. The gallery is static but updates every 60 seconds. Serve the cached page instantly, regenerate in the background. Best of both worlds.
📁
File-Based Routing
app/gallery/page.tsx → /gallery. No React Router config. Create a file → get a route. Nested folders → nested routes. Layout files → shared layouts. The file system IS the router.
HANDS-ON.TASKS
01
Create the Next.js Project
npx create-next-app@latest \ pixelcraft-web \ --typescript \ --tailwind \ --app
02
Public Gallery — Server Component
// app/gallery/page.tsx // Server Component — runs on server import { ImageGrid } from '@/components/ImageGrid'; async function getPublicImages() { const res = await fetch( `${process.env.API_URL}` + `/api/images/public`, { next: { revalidate: 60 }, // ↑ Regenerate every 60 seconds }); return res.json(); } export default async function GalleryPage() { const images = await getPublicImages(); return ( <main className="max-w-7xl mx-auto px-4 py-8"> <h1 className="text-3xl font-bold mb-8"> Public Gallery </h1> <ImageGrid images={images} /> </main> ); } // SEO metadata export const metadata = { title: 'PixelCraft Gallery' + ' — Community Creations', description: 'Explore images edited with' + ' PixelCraft...', openGraph: { images: ['/og-gallery.jpg'] }, };
This component is async and fetches data directly — no useEffect, no loading state. The server fetches data, renders HTML, sends it complete. The browser receives a fully rendered page.
03
Marketing Landing Page — SSG
// app/page.tsx // Static — generated at build time export default function LandingPage() { return ( <main> <section className="h-screen flex items-center justify-center"> <div className="text-center"> <h1 className="text-6xl font-bold"> PixelCraft </h1> <p className="text-xl text-slate-400 mt-4"> Professional image editing in your browser </p> <a href="/editor" className="mt-8 inline-block bg-cyan-600 px-8 py-3 rounded-lg"> Start Editing — Free </a> </div> </section> </main> ); } // No data fetching = static page. // Built once at deploy time. // Served from CDN. Instant load.
04
Verify: View Source
// Right-click → View Page Source // ❌ SPA (before): <html> <body> <div id="root"></div> <script src="/bundle.js"></script> </body> </html> // Google sees: nothing. // ✅ Next.js SSR (after): <html> <body> <main> <h1>Public Gallery</h1> <div class="grid"> <img src="..." alt="Sunset" /> <img src="..." alt="Portrait" /> ...500 more images rendered... </div> </main> </body> </html> // Google sees: everything.
05
Close the Ticket
git switch -c feature/PIXELCRAFT-087-nextjs-ssr git add pixelcraft-web/ git commit -m "Add Next.js SSR gallery + landing page (PIXELCRAFT-087)" git push origin feature/PIXELCRAFT-087-nextjs-ssr # PR → Review → Merge → Close ticket ✅
CS.DEEP-DIVE

The rendering spectrum: every strategy is a tradeoff.

Next.js lets you mix all four strategies in one application — different pages use different strategies based on their needs.

// The rendering spectrum:

CSR (Client-Side Rendering)
  Browser downloads empty HTML + JS
  JS renders the page
  Slow first paint, no SEO

SSR (Server-Side Rendering)
  Server renders HTML per request
  Fast first paint, always fresh
  Server cost per request

SSG (Static Site Generation)
  HTML generated at build time
  Fastest: static files from CDN
  Can't update without rebuild

ISR (Incremental Static Regen)
  Static + re-generates periodically
  Fast delivery, eventual freshness
  Best of SSG + SSR

// PixelCraft uses all four:
// Landing → SSG (never changes)
// Gallery → ISR (updates hourly)
// Editor → CSR (interactive)
// Profile → SSR (always fresh)
"SSR Lab"
[A]Add dynamic OG images: app/api/og/route.tsx generates a custom Open Graph image for each gallery item using @vercel/og. Share a link → see a beautiful preview card with the image title and thumbnail.
[B]Add a dynamic [imageId] page: app/gallery/[id]/page.tsx. Fetch a single image, render with full metadata. Use generateStaticParams() to pre-generate the top 100 most popular images at build time.
[C]Research: compare Next.js vs Remix vs Astro vs SvelteKit. When would you choose each? What are their rendering strategies, data loading patterns, and deployment targets? Write a comparison document.
REF.MATERIAL
ARTICLE
Vercel
Official Next.js guide: App Router, Server Components, data fetching, routing, middleware, and deployment. The canonical reference.
NEXTJSOFFICIALESSENTIAL
VIDEO
Fireship
Ultra-fast Next.js overview: SSR, SSG, API routes, file-based routing. Why it's the most popular React framework.
NEXTJSQUICK
ARTICLE
Vercel
How Server Components work: rendering on the server, streaming, interleaving with Client Components. The React paradigm shift.
RSCOFFICIAL
ARTICLE
Google
CSR vs SSR vs SSG vs streaming: performance characteristics, tradeoffs, and when to use each. The rendering spectrum explained.
RENDERINGTHEORYESSENTIAL
VIDEO
JavaScript Mastery
Comprehensive Next.js 14 tutorial: App Router, Server Actions, data fetching patterns, authentication, and deployment.
NEXTJSTUTORIAL
// LEAVE EXCITED BECAUSE
View source → fully rendered HTML. Google can crawl it. Social media shows rich previews. The landing page loads in under 1 second. Next.js is the industry standard for a reason.