404 Not Found

404 Not Found


nginx

Introduction to Nuxt 3 and the Concept of SSR

Charlie is selecting a tech stack for his e-commerce platform, MegaShop—with millions of product pages, he needs top-notch SEO, and the page must load quickly on the first screen. Traditional CSR solutions prevent search engines from crawling product data, resulting in dismal traffic. Nuxt 3's SSR capabilities are exactly what he needs.

1. What You'll Learn


2. A True Story of an Architect

(1) Pain Point: CSR Makes Millions of Product Pages "Invisible"

Charlie's MegaShop has over 1 million product pages, but after switching to pure CSR (client-side rendering), Google's crawler could only retrieve an empty <div id="app"></div>—with product titles, prices, and descriptions all missing. SEO rankings plummeted to page 5; Alice (the consumer) couldn't find the products at all, and Bob (the administrator) was worried about the near-zero organic traffic.

(2) Solutions for Nuxt 3 SSR

Nuxt 3 server-sidesrenders HTML, so crawlers receive the complete product page—complete with the title, price, and structured data. Charlie just needs to create a project, and SSR is ready to go right out of the box:

BASH
# Create Nuxt 3 project with SSR enabled by default
npx nuxi@latest init megashop

(3) Benefits: A Surge in SEO Traffic

After switching to Nuxt 3 SSR, MegaShop's Google index pages surged from 2,000 to 800,000, organic traffic grew by 340%, and above-the-fold load time dropped from 4.2 seconds to 1.1 seconds.


3. The Relationship Between Nuxt 3 and Vue 3

Nuxt 3 is a full-stack framework based on Vue 3, led by Sébastien Chopin, a member of the Vue core team.

(1) Positioning Comparison

Dimension Vue 3 Nuxt 3
Positioning Progressive UI Framework Vue 3 Full-Stack Meta-Framework
Rendering CSR Only SSR / CSR / SSG / ISR / ESR
Routes Manually configure vue-router Automatically generated file routes
Data Retrieval Manual Wrapping useFetch / useAsyncData
Build Requires Vite/Webpack Built-in Vite
Server-side None Nitro Server Engine
Auto-import None Components/Composables/Utility Functions

(2) The Core Value of Nuxt 3

💡 Tip: Nuxt 3 is not a replacement for Vue 3, but rather an enterprise-grade framework that builds on Vue 3 to provide full-stack engineering capabilities.


4. Comparison of Five Rendering Modes

(1) Panoramic View of Rendering Modes

100%
flowchart TB
    A[User Request] --> B{Rendering Mode}
    B -->|SSR| C[Server renders HTML<br/>on every request]
    B -->|CSR| D[Browser renders HTML<br/>after JS download]
    B -->|SSG| E[HTML pre-built<br/>at build time]
    B -->|ISR| F[HTML cached +<br/>revalidate on interval]
    B -->|ESR| G[Edge CDN renders<br/>closest to user]
    C --> H[Full HTML response]
    D --> I[Empty shell + JS bundle]
    E --> H
    F --> H
    G --> H

(2) Key Comparisons of the Five Models

Dimension SSR CSR SSG ISR ESR
Rendering Timing Per Request Browser-Side Build Time Cache + Periodic Validation CDN Edge Node
SEO-Friendly ✅ Excellent ❌ Poor ✅ Excellent ✅ Excellent ✅ Excellent
First-Screen Load Speed ⚡ Fast 🐢 Slow ⚡⚡ Fastest ⚡⚡ Fast ⚡⚡⚡ Fastest
Data Real-Time Status ✅ Real-time ✅ Real-time ❌ Static ⚠️ Scheduled updates ⚠️ Scheduled updates
Server Load 🔴 High 🟢 Low 🟢 Lowest 🟡 Medium 🟡 Medium
Use Cases Dynamic Detail Pages Backend Management Blog/Documentation Product Lists Internationalized Pages

(3) A Detailed Explanation of the SSR Workflow

SSR (Server-Side Rendering) is the default rendering mode in Nuxt 3. The core process is as follows:

  1. User Request URL
  2. Rendering Vue Components on the Nuxt Server-Side
  3. Generate a complete HTML string
  4. Send HTML to the browser
  5. Browser display page (visible on the first screen)
  6. Download the JS file, "hydrate" it, and bind events

(1) ▶ Example: Comparison of SSR and CSR Responses

HTML
<!-- SSR response: full HTML with content -->
<div id="app">
  <h1>MegaShop - Premium Headphones</h1>
  <p>Price: $299.99 USD</p>
  <p>1.2 thousand reviews</p>
</div>

<!-- CSR response: empty shell -->
<div id="app"></div>
<script src="/bundle.js"></script>

Output:

TEXT
// Execution Successful

(2) ▶ Example: Nuxt 3 SSR Page

VUE
<!-- pages/index.vue -->
<template>
  <div>
    <h1>{{ product.name }}</h1>
    <p>Price: ${{ product.price }} USD</p>
  </div>
</template>

<script setup lang="ts">
// Data fetched on server, included in HTML response
const { data: product } = await useFetch('/api/products/featured')
</script>

Output:

TEXT
// Execution Successful

(3) ▶ Example: CSR Mode Page

VUE
<!-- pages/dashboard.vue - client-only page -->
<template>
  <div>
    <h1>Admin Dashboard</h1>
    <p>Welcome, Bob</p>
  </div>
</template>

<script setup lang="ts">
// Force client-side rendering
definePageMeta({
  ssr: false
})

const { data: stats } = await useFetch('/api/admin/stats')
</script>

Output:

TEXT
// Execution Successful

5. Nuxt 3 Core Architecture

(1) Architecture Components

100%
graph TB
    A[Nuxt 3] --> B[Vite - Build Tool]
    A --> C[Vue 3 - UI Framework]
    A --> D[Nitro - Server Engine]
    A --> E[Auto-imports System]
    D --> F[H3 - HTTP Framework]
    D --> G[Storage Layer]
    D --> H[Cache API]
    E --> I[Components]
    E --> J[Composables]
    E --> K[Utilities]

(2) Core Module Responsibilities

Module Responsibilities MegaShop Application
Vite Build tool, HMR (Hyper-Fast Hot Reload) Refresh product pages in seconds during development
Vue 3 Composition API + Reactivity Component-Based Product Cards/Shopping Cart
Nitro Server-side engine, multiple preset deployments API routing + ISR caching
Auto-imports Automatic Component/Function Registration Use useFetch Directly Without import
H3 Lightweight HTTP Framework Handling API Requests and Middleware

(1) ▶ Example: How Auto-imports Work

VUE
<!-- No manual imports needed -->
<template>
  <div>
    <ProductCard :product="item" />
    <!-- ProductCard auto-imported from components/ -->
  </div>
</template>

<script setup lang="ts">
// useFetch, useState, useRouter - all auto-imported
const { data: item } = await useFetch('/api/products/1')
const router = useRouter()
const cart = useState('cart', () => [])
</script>

Output:

TEXT
// Execution Successful

(2) ▶ Example: Nitro API Route

TYPESCRIPT
// server/api/products/index.ts
export default defineEventHandler(async (event) => {
  const query = getQuery(event)
  const page = Number(query.page) || 1
  const limit = Number(query.limit) || 20

  // Fetch products with pagination
  const products = await fetchProducts(page, limit)

  return {
    items: products,
    total: 1000000, // 1 million products
    page,
    limit
  }
})

Output:

TEXT
// Execution Successful

6. MegaShop Scenario Analysis

(1) Why Must Product Pages with Millions of Items Use SSR?

Demand CSR Performance SSR Performance
Google Indexing Rate < 5% > 95%
First-Screen LCP 3.5-5 s 0.8-1.5 s
Product name appears in HTML ❌ Requires JS ✅ Included directly
Structured Data Support ❌ Not visible to crawlers ✅ Full output
Social Sharing Preview ❌ Blank ✅ Displays Correctly

(1) ▶ Example: MegaShop Product Page SSR Output

HTML
<!-- Server-rendered HTML for /products/headphones-123 -->
<!DOCTYPE html>
<html>
<head>
  <title>Premium Headphones - MegaShop</title>
  <meta name="description" content="Premium wireless headphones, $299.99 USD">
  <script type="application/ld+json">
  {
    "@type": "Product",
    "name": "Premium Headphones",
    "price": "299.99",
    "priceCurrency": "USD",
    "aggregateRating": { "ratingValue": "4.8", "reviewCount": "1200" }
  }
  </script>
</head>
<body>
  <div id="app">
    <h1>Premium Headphones</h1>
    <p>$299.99 USD</p>
    <p>1.2 thousand reviews · 4.8 stars</p>
  </div>
</body>
</html>

Output:

TEXT
// Execution Successful

7. An Overview of the Nuxt 3 Ecosystem

(1) Official Module Ecosystem

Module Function Use in MegaShop
@nuxtjs/tailwindcss CSS Framework Integration Responsive Layout
@nuxt/image Image Optimization WebP Conversion + Lazy Loading
@nuxtjs/i18n Internationalization Chinese/English/Japanese
@nuxtjs/sitemap Sitemap Generation SEO for Millions of Pages
@pinia/nuxt State Management Shopping Cart/User State
@nuxt/devtools Developer Tools Debugging and Performance Analysis

(2) Community Size

(1) ▶ Example: Installing an Official Module

BASH
# Install Tailwind CSS module
npm install @nuxtjs/tailwindcss

# Install Pinia state management
npm install @pinia/nuxt

# Install i18n module
npm install @nuxtjs/i18n

Output:

TEXT
# Command executed successfully
TYPESCRIPT
// nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    '@nuxtjs/tailwindcss',
    '@pinia/nuxt',
    '@nuxtjs/i18n'
  ]
})

8. Comprehensive Example: MegaShop SSR Product Page

VUE
<!-- pages/products/[id].vue -->
<template>
  <div class="product-page">
    <h1>{{ product?.name }}</h1>
    <p class="price">${{ product?.price }} USD</p>
    <p>{{ product?.reviewCount }} reviews</p>
    <button @click="addToCart(product)">
      Add to Cart
    </button>
  </div>
</template>

<script setup lang="ts">
interface Product {
  id: number
  name: string
  price: number
  reviewCount: number
}

// SSR: data fetched on server, included in initial HTML
const route = useRoute()
const { data: product } = await useFetch<Product>(`/api/products/${route.params.id}`)

// SEO metadata
useHead({
  title: `${product.value?.name} - MegaShop`,
  meta: [
    { name: 'description', content: `Buy ${product.value?.name} for $${product.value?.price} USD` }
  ]
})

const cart = useState<Product[]>('cart', () => [])
function addToCart(item: Product | null) {
  if (item) cart.value.push(item)
}
</script>

❓ FAQ

Q What is the difference between Nuxt 3 and Next.js?
A Nuxt 3 is based on Vue 3 + Vite, while Next.js is based on React + Webpack/Turbopack. Nuxt 3 offers more comprehensive auto-imports and file conventions, and its Nitro engine supports more deployment presets.
Q Will SSR put a heavy load on the server?
A For high-traffic pages, you can use ISR caching or ESR edge rendering to reduce the load on the server. Nuxt 3's routeRules allow you to configure the rendering strategy independently for each route.
Q Can I use Nuxt 3 without SSR?
A Yes. You can disable SSR globally by setting ssr: false in nuxt.config.ts, or disable it for individual pages using definePageMeta. Admin pages typically use CSR.
Q Can I use browser APIs on an SSR page?
A There is no browser environment during the SSR phase, so using window or document directly will result in an error. You need to place the code within the onMounted hook or use import.meta.client to check the environment.
Q Does Nuxt 3 support TypeScript?
A It has native support. Nuxt 3 automatically generates .nuxt/tsconfig.json, and components, composables, and APIs all have full type inference, so no manual configuration is required.
Q How does MegaShop ensure fast page-building speeds for its millions of product pages?
A We don't pre-build all pages. We use server-side rendering (SSR) on a per-request basis combined with in-browser rendering (ISR) to cache popular pages. During the build process, we only pre-render key pages (homepage/category pages), while product detail pages use SSR + ISR.

📖 Summary


📝 Exercises

  1. Basic Exercise (Difficulty: ⭐): Use npx nuxi@latest init to create a Nuxt 3 project and check whether SSR is enabled in the default configuration.
  2. Advanced Exercise (Difficulty: ⭐⭐): Use useFetch on the project homepage to retrieve data from a public API, then check whether the data is included in the browser's "View Source" (to verify SSR).
  3. Challenge (Difficulty: ⭐⭐⭐): Create a page using the CSR mode (definePageMeta({ ssr: false })) and compare the differences between it and an SSR page when viewing the source code.

---|

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏