[ skills ]
choose-nextjs-or-vite
Decide con criterio técnico cuándo conviene usar Next.js (SSR/RSC) y cuándo basta un frontend ligero en React + Vite, sobre todo si ya tienes un backend aparte o tu app vive detrás de un login.
npx skills add OmarAlex24/skills --skill choose-nextjs-or-vite agentes: claude-code · codex · cursor · opencode · antigravity
Choose Next.js vs. React + Vite (Don’t Pay for an Extra Server You Don’t Need)
Help developers evaluate whether a React application genuinely benefits from Next.js (SSR, React Server Components, App Router runtime) or whether a plain React + Vite static build talking directly to an existing API is simpler, faster to develop, and cheaper to run in production.
Language rule (mandatory): Always match the language the user is speaking in (for example, reply, interview, and write recommendations in Spanish if the user writes in Spanish). Keep framework names, file/build terms (
vite build,dist/,SSR,RSC,SPA,CDN), and technical concepts accurate.
Step 1: Audit the App Shape (4 Questions)
Inspect the repository first (or ask only what is missing):
- Backend topology: Is there already a separate backend service (Go, Python, Node/Nest/Fastify, Rust, Rails, etc.) handling business logic, auth, and database access — or does the team want the frontend framework to act as the full-stack backend too?
- Access boundary: Does the core app live behind a login (internal admin panel, B2B dashboard, private SaaS workspace) or on public URLs that search engines and social crawlers must index?
- First-load sensitivity: Is initial anonymous page load (public landing, catalog, blog, e-commerce) a conversion bottleneck where shipping HTML already populated with server data matters?
- Hosting & ops preference: Can the frontend be deployed as static files (
dist/on Cloudflare Pages, S3 + CloudFront, Netlify, etc.), or is the team willing to run and bill a Node.js / serverless SSR runtime?
Step 2: Apply the Decision Matrix
| Project profile | Default choice | Why |
|---|---|---|
| Separate backend + behind login (dashboards, internal tools, B2B SaaS workspaces) | React + Vite (SPA) | Avoids maintaining a second server hop (Browser → Next.js → Your API), removes SSR/hydration complexity, compiles to lightweight static assets (dist/), deploys nearly for free on a global CDN, and talks directly to your API. |
| Public content & SEO-critical sites (blogs, marketing pages, docs, directories) | Next.js | Search engines and AI/social crawlers receive complete server-rendered HTML with dynamic metadata and Open Graph previews. |
| E-commerce / public catalogs | Next.js | Fast first paint with server-fetched product data, crawlable product pages, and clean link previews. |
| No separate backend (unified full-stack JS/TS) | Next.js (or another full-stack framework) | When you intentionally want API routes / Server Actions / RSC data fetching in one deployable unit without standing up a separate backend. |
| Hybrid product (public marketing site + private app) | Split them | Keep the public marketing/docs site on Next.js (or static Astro/MDX) for SEO, and run the authenticated app (app.domain.com) as a lean React + Vite SPA talking directly to your API. |
Step 3: Key Architectural Tradeoffs & Caveats
- The double-hop trap: Putting a Next.js SSR runtime in front of an existing Go/Python/Node API often adds latency, duplicate auth/session plumbing, extra serverless compute billing, and another deployment surface to debug.
- Google doesn’t index behind a login: Running SSR solely “for SEO” on routes behind authentication delivers zero SEO benefit while keeping all the complexity of Server/Client boundaries and hydration mismatches.
- Static export caveat (
output: 'export'): Next.js supports static export, but enabling it disables dynamic SSR, Server Actions, Middleware, and dynamic server rendering. If you end up disabling Next.js’s server features, React + Vite gives a much faster local dev loop and a smaller mental model. - Where Next.js genuinely wins: Eliminating the client data-fetching waterfall (
download JS → mount → spinner → fetch API) on public entry pages by delivering HTML already populated from the server (SSR / RSC).
Step 4: Deliverable
Produce a concise Frontend Architecture Decision in the user’s language:
- Verdict:
React + Vite (SPA),Next.js, orSplit (Public site + Vite App)— tied directly to their backend topology, login boundary, and SEO needs. - Request flow diagram: Show the concrete path (
Browser (CDN) → APIvs.Browser → Next.js Server → DB/API). - Minimal starter stack:
- If React + Vite: Vite + React + lightweight router (React Router / TanStack Router) + data cache (TanStack Query) + static CDN hosting.
- If Next.js: define explicitly which routes need SSR/RSC/metadata and keep authenticated interactive views cleanly separated as client boundaries.
- Migration / sanity check (if already on Next.js): Flag whether migrating away is worth the churn right now, or if simply keeping the current setup while avoiding extra middleware/SSR overhead is more pragmatic.