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.
Deploy to Vercel (Recommended)
Vercel made Next.js, so deployment is literally push to git and done:
Terminal
bash
1# 1. Push your code to GitHub/GitLab/Bitbucket2git add .3git commit -m "Ready for production"4git push origin main56# 2. Go to vercel.com, import your repo7# 3. Click Deploy8# 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
⢠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# Dockerfile2FROM node:20-alpine AS builder3WORKDIR /app4COPY package*.json ./5RUN npm ci6COPY . .7RUN npm run build89FROM node:20-alpine AS runner10WORKDIR /app11COPY --from=builder /app/.next/standalone ./12COPY --from=builder /app/.next/static ./.next/static13COPY --from=builder /app/public ./public1415EXPOSE 300016CMD ["node", "server.js"]next.config.ts
tsx
1// next.config.ts - enable standalone output for Docker2import type { NextConfig } from "next";34const nextConfig: NextConfig = {5output: "standalone",6};78export 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 needed2import dynamic from "next/dynamic";34const HeavyChart = dynamic(() => import("@/components/Chart"), {5loading: () => <p>Loading chart...</p>,6ssr: false, // Don't render on server if it uses window/document7});89export 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
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