Back to Templates

Nuxt Hybrid Rendering Template

A Nuxt site, using the mix render starter kit.

View Demo
FrameworkNuxt.js
Use CaseStarter
A Nuxt site, using the mix render starter kit.

Nuxt.js Hybrid Rendering Example Project

๐Ÿš€ A complete Nuxt.js hybrid rendering example project showcasing the practical applications and best practices of SSG, ISR, and SSR rendering modes.

โœจ Project Features

  • ๐ŸŽฏ Three Rendering Mode Demos: Complete examples of SSG, ISR, and SSR
  • ๐ŸŽจ Modern UI Design: Beautiful interface based on Nuxt's official green theme
  • ๐Ÿ“ฑ Responsive Design: Perfect adaptation for desktop and mobile
  • โšก Performance Optimization: Performance optimization strategies for different rendering modes
  • ๐Ÿ”ง TypeScript Support: Complete type-safe development experience
  • ๐Ÿ“Š Real-time Data Display: Dynamic data and real-time updates on SSR pages
  • ๐Ÿ”„ Incremental Updates: Smart caching and on-demand updates for ISR pages

๐Ÿ—๏ธ Project Structure

โ”œโ”€โ”€ app/
โ”‚   โ””โ”€โ”€ app.vue                 # Application entry point
โ”œโ”€โ”€ assets/
โ”‚   โ””โ”€โ”€ css/
โ”‚       โ””โ”€โ”€ main.css           # Main stylesheet (Nuxt green theme)
โ”œโ”€โ”€ layouts/
โ”‚   โ””โ”€โ”€ default.vue            # Default layout
โ”œโ”€โ”€ pages/
โ”‚   โ”œโ”€โ”€ index.vue              # Home page (SSG)
โ”‚   โ”œโ”€โ”€ ssg.vue                # SSG example page
โ”‚   โ”œโ”€โ”€ isr.vue                # ISR example page
โ”‚   โ””โ”€โ”€ ssr.vue                # SSR example page
โ”œโ”€โ”€ server/
โ”‚   โ””โ”€โ”€ api/
โ”‚       โ”œโ”€โ”€ ssr-data.ts        # SSR dynamic data API
โ”‚       โ””โ”€โ”€ isr-content.ts     # ISR content API
โ”œโ”€โ”€ nuxt.config.ts             # Nuxt configuration (hybrid rendering rules)
โ””โ”€โ”€ package.json

๐ŸŽฏ Rendering Mode Comparison

FeatureSSGISRSSR
First Loadโšก Extremely Fast (<100ms)๐Ÿš€ Fast (~120ms)๐Ÿ“Š Medium (~300ms)
Content Freshness๐Ÿ”„ Requires Rebuildโœ… Auto Updateโœ… Real-time
Server Loadโœ… None๐Ÿ“‰ Low๐Ÿ“ˆ High
SEO Friendlyโœ… Perfectโœ… Perfectโœ… Good
Use CasesDocs, CorporateBlog, E-commerceDashboard, Social

๐Ÿš€ Quick Start

Requirements

  • Node.js 18+
  • npm / yarn / pnpm

Install Dependencies

# Using npm
npm install

# Using yarn
yarn install

# Using pnpm
pnpm install

Development Environment

Start the development server at http://localhost:3000:

# Using npm
npm run dev

# Using yarn
yarn dev

# Using pnpm
pnpm dev

Production Build

# Build application
npm run build

# Generate static site
npm run generate

# Preview production build
npm run preview

๐Ÿ“– Page Descriptions

๐Ÿ  Home Page (/)

  • Rendering Mode: SSG (Static Site Generation)
  • Features: Generated at build time, fastest loading speed
  • Content: Project introduction, tech stack showcase, quick start guide

โšก SSG Example (/ssg)

  • Rendering Mode: SSG (Static Site Generation)
  • Features: Demonstrates SSG principles, performance advantages and configuration methods
  • Content: Technical principles, performance comparison, use cases, code examples

๐Ÿ”„ ISR Example (/isr)

  • Rendering Mode: ISR (Incremental Static Regeneration)
  • Features: Combines advantages of static generation and dynamic updates
  • Content: Real-time content display, working principles, configuration examples, advantage comparison

๐Ÿš€ SSR Example (/ssr)

  • Rendering Mode: SSR (Server-Side Rendering)
  • Features: Real-time data, dynamic content, personalized experience
  • Content: Real-time dashboard, user activity, system status, API call demonstrations

โš™๏ธ Configuration

Nuxt Configuration (nuxt.config.ts)

export default defineNuxtConfig({
  // CSS Configuration
  css: ['~/assets/css/main.css'],
  
  // Hybrid Rendering Route Rules
  routeRules: {
    '/': { prerender: true },        // SSG - Home
    '/ssg': { prerender: true },     // SSG - Static Generation
    '/isr': { isr: true },           // ISR - Incremental Static Regeneration
    '/ssr': { ssr: true }            // SSR - Server-Side Rendering
  },
  
  // TypeScript Configuration
  typescript: {
    strict: true,
    typeCheck: true
  }
})

API Routes

/api/ssr-data - SSR Dynamic Data

  • Provides real-time statistics
  • User activity information
  • System status monitoring
  • Regenerated on every request

/api/isr-content - ISR Content Data

  • Article lists
  • Product information
  • Statistics data
  • Periodically updated with smart caching

๐ŸŽจ Style System

The project uses a complete design system based on Nuxt's official green theme:

  • Primary Color: #00DC82 (Nuxt Green)
  • CSS Variables: Unified color, spacing, and shadow system
  • Responsive Design: Mobile-first layout strategy
  • Component Styles: Cards, buttons, badges and other common components

๐Ÿ“Š Performance Optimization

SSG Optimization

  • Pre-generate all pages at build time
  • Static asset CDN distribution
  • Image lazy loading and optimization
  • CSS/JS code splitting

ISR Optimization

  • Smart caching strategies
  • On-demand regeneration
  • Background update mechanisms
  • Cache invalidation control

SSR Optimization

  • Server-side data prefetching
  • Client-side hydration optimization
  • API response caching
  • Component-level caching

๐Ÿš€ Deployment Guide

Static Deployment (SSG)

Suitable for Netlify, Vercel, GitHub Pages and other static hosting services:

npm run generate

Server Deployment (Hybrid Rendering)

Suitable for Node.js-supported server environments:

npm run build
npm run preview

๐Ÿ› ๏ธ Tech Stack

๐Ÿ“š Learning Resources

๐Ÿค Contributing

Welcome to submit Issues and Pull Requests!

  1. Fork this repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is open source under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Nuxt.js - Excellent full-stack Vue framework
  • Vue.js - Progressive JavaScript framework
  • All developers who contribute to the open source community