← Back to chapters
15advanced

Deployment & Production

Deploy to Vercel, self-host, bundle analysis, performance tips, and production checklist.

Taking Your App to Production

You've built something great. Now let's get it live. I'll cover Vercel (easiest), self-hosting, and optimization tips that actually matter.

Vercel made Next.js, so deployment is literally push to git and done:

Terminal
bash
1# 1. Push your code to GitHub/GitLab/Bitbucket
2git add .
3git commit -m "Ready for production"
4git push origin main
5
6# 2. Go to vercel.com, import your repo
7# 3. Click Deploy
8# That's it. Seriously.
šŸ’”

What Vercel gives you

Automatic HTTPS, global CDN, serverless functions, edge middleware:
• Preview deployments for every PR
• Built-in analytics
• Zero-config setup
• Free tier is generous for personal projects

Self-Hosting with Docker

Dockerfile
dockerfile
1# Dockerfile
2FROM node:20-alpine AS builder
3WORKDIR /app
4COPY package*.json ./
5RUN npm ci
6COPY . .
7RUN npm run build
8
9FROM node:20-alpine AS runner
10WORKDIR /app
11COPY --from=builder /app/.next/standalone ./
12COPY --from=builder /app/.next/static ./.next/static
13COPY --from=builder /app/public ./public
14
15EXPOSE 3000
16CMD ["node", "server.js"]
next.config.ts
tsx
1// next.config.ts - enable standalone output for Docker
2import type { NextConfig } from "next";
3
4const nextConfig: NextConfig = {
5output: "standalone",
6};
7
8export default nextConfig;

Performance Checklist

FeatureWhat it doesWhen to use
ImagesUse next/image everywhereAuto WebP + lazy load
FontsUse next/fontZero layout shift
BundleDynamic imports for heavy libsSmaller initial JS
CachingSet revalidation on fetchesFaster repeat visits
ComponentsServer Components by defaultLess client JS
3rd partyUse next/script with strategyDon't block render
Dynamic import example
tsx
1// Dynamic import, only loads when needed
2import dynamic from "next/dynamic";
3
4const HeavyChart = dynamic(() => import("@/components/Chart"), {
5loading: () => <p>Loading chart...</p>,
6ssr: false, // Don't render on server if it uses window/document
7});
8
9export default function AnalyticsPage() {
10return (
11 <div>
12 <h1>Analytics</h1>
13 <HeavyChart />
14 </div>
15);
16}
šŸš€

My production checklist

Before deploying:
1) Run 'npm run build' locally to catch errors
2) Check bundle size with @next/bundle-analyzer
3) Test with Lighthouse
4) Ensure all images use next/image
5) Set up error monitoring (Sentry)
6) Add proper metadata for SEO

ā–¶Watch and Learn