Back to Templates
Nuxt Hybrid Rendering Template
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
| Feature | SSG | ISR | SSR |
|---|---|---|---|
| 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 Cases | Docs, Corporate | Blog, E-commerce | Dashboard, 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
- Framework: Nuxt.js 4.1.3
- Frontend: Vue.js 3.5.22
- Language: TypeScript
- Build Tool: Vite
- Styling: Native CSS + CSS Variables
๐ Learning Resources
- Nuxt.js Official Documentation
- Vue.js Official Documentation
- Rendering Mode Comparison
- Hybrid Rendering Configuration
๐ค Contributing
Welcome to submit Issues and Pull Requests!
- Fork this repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This project is open source under the MIT License - see the LICENSE file for details.