Next.js in 100 Seconds // Plus Full Beginner's Tutorial

Original Media · 12m · English · YouTube

TLDR

This Fireship tutorial introduces Next.js as a React framework that solves client-side rendering's SEO and performance drawbacks by enabling server-side rendering. It demonstrates file-based routing, dynamic routes, and three data fetching strategies: static generation (getStaticProps/getStaticPaths) for pre-rendering at build time, server-side rendering (getServerSideProps) for fresh data on each request, and incremental static regeneration for a hybrid approach. The video includes live coding examples showing how to fetch data, handle dynamic routes, and optimize SEO with the Head component. The presenter emphasizes that Next.js lets you mix rendering strategies page-by-page within a single application.

For you

PRO members can sign in and request more information — or their own version of this digest, tuned to what they care about.

Sign in to unlock

Surprising Insights

•

You can mix static generation and server-side rendering page-by-page within the same Next.js application rather than committing to one strategy globally.

•

Dynamic routes require explicitly listing all possible paths at build time via getStaticPaths, meaning Next.js cannot automatically discover dynamic routes from a database — you must fetch and return the full path list yourself.

•

The same data fetching code (fetch + JSON parsing) works identically in both getStaticProps and getServerSideProps; only the function name and execution timing differ.

Key takeaways

•

Next.js eliminates client-side rendering's SEO and performance issues by pre-rendering HTML on the server, so search bots and users receive fully rendered content immediately before JavaScript hydration takes over.

•

File-based routing in the pages directory automatically maps file structure to URLs — index.js becomes the root route, nested directories create nested routes, and bracket syntax like [id].js creates dynamic route parameters accessible via the useRouter hook.

•

Static generation via getStaticProps runs at build time, producing HTML files that can be cached on a CDN for maximum performance, but requires getStaticPaths to predefine all dynamic routes and becomes impractical for sites with millions of pages or frequently changing data.

•

Server-side rendering via getServerSideProps executes on every request, guaranteeing fresh data for use cases like auction sites or dashboards, but requires a running server and cannot leverage global CDN caching like static generation.

•

Incremental static regeneration bridges both strategies by adding a revalidate option to getStaticProps, allowing Next.js to serve stale cached HTML while regenerating the page in the background after a specified time interval.

•

The Head component enables per-page SEO metadata like titles and Open Graph tags that are rendered into the document head during server-side rendering, critical for search engine indexing and social media link previews.

•

API routes in the pages/api directory run exclusively on the server, keeping sensitive logic and database credentials out of the client bundle while enabling full-stack functionality within a single Next.js project.

•

CSS Modules are supported out of the box — global styles go in globals.css while component-scoped styles use the .module.css suffix, eliminating naming collisions without requiring CSS-in-JS solutions.

Notable quotes

“next is a framework that allows you to build a react app but render the content in advance on the server so the first thing a user or search bot sees is the fully rendered html”

▸ Notable quotes · 0:32

“static generation is also called pre-rendering because you generate all the html at build time it makes life very simple because you generate a bunch of html files then upload them to a storage bucket or static host and they can be delivered with very high performance over a cdn”

▸ Notable quotes · 6:52

“the big difference is that with ssr the content is generated on a server when requested by the user this approach is ideal when data changes constantly because it ensures the end user will always get the latest and greatest data from whatever your data source happens to be”

▸ Notable quotes · 10:33

“but the real beauty of next is that we can apply both of these paradigms wherever we want in the application we're not limited to one or the other”

▸ Notable quotes · 11:32

“if you're concerned about search engine optimization you likely want to add an seo friendly title as well as meta tags to the head of the document next makes that very easy to accomplish by simply importing the head component”

▸ Notable quotes · 8:58

“the api directory is a special part of next for setting up routes that will only apply to the server that can be useful because the code you write here won't increase the client-side javascript bundle that needs to ultimately be sent over the network”

▸ Notable quotes · 6:02

Chapters

•

0:05 — Client-Side Rendering Drawbacks: Explains how traditional React apps render in the browser, causing SEO issues and slower first contentful paint.

•

0:32 — Next.js Server-Side Rendering Overview: Introduces Next.js as a framework that pre-renders HTML on the server for bots and users, then hydrates on the client.

•

2:41 — File-Based Routing and Project Setup: Demonstrates creating a Next.js app, the pages directory structure, and how files map to routes including dynamic routes with bracket syntax.

•

4:50 — Dynamic Routes and useRouter Hook: Shows creating dynamic routes with [id].js files and accessing URL parameters via the useRouter hook from next/router.

•

5:59 — API Routes for Server-Only Code: Explains the pages/api directory for server-only endpoints that don't bloat the client bundle.

•

6:28 — Static Generation with getStaticProps and getStaticPaths: Walks through implementing getStaticProps to fetch data at build time and getStaticPaths to define dynamic routes for pre-rendering.

•

8:59 — SEO Optimization with Head Component: Shows how to add page-specific titles and meta tags using Next's Head component for search engines and social sharing.

•

10:30 — Server-Side Rendering with getServerSideProps: Contrasts SSR with static generation, showing how getServerSideProps runs on each request for fresh data, and demonstrates switching between strategies.

Speakers

•

Narrator — Instructor

⋮