| | |

Nuxt 09 ๐Ÿ’š Rendering Modes & Hybrid Rendering โ€” SSR, SSG, CSR, and routeRules

โฑ๏ธ Estimated read: 9 min | |

Nuxt is built on a rendering engine that allows for total flexibility. In older architectures, you had to choose a rendering mode for the entire application: either everything was rendered on the server, or everything was rendered in the browser. Nuxt breaks this binary. With its hybrid rendering architecture, you can define the rendering strategy on a per-route basis using the routeRules configuration. You can have a marketing landing page that is pre-rendered at build time, a dashboard that renders on-demand on the server, and a private user settings page that renders entirely in the client’s browser.

The engine behind this is Nitro, which intercepts incoming requests and applies the rendering strategy you defined for that specific URL. This chapter explores the spectrum of rendering modes available in Nuxt. We will cover Universal SSR (the default), Static Site Generation (SSG) via nuxt generate, Client-Side Rendering (CSR) by disabling SSR, and the powerful caching mechanisms known as SWR (Stale-While-Revalidate) and ISR (Incremental Static Regeneration).

Key point: Nuxtโ€™s hybrid rendering strategy is defined via routeRules in nuxt.config.ts, allowing you to mix rendering modesโ€”SSR, SSG, SWR, and SPAโ€”within the same application, giving you the granularity to optimize each route for its specific performance and SEO requirements.


Why rendering modes exist

The build-time bottleneck. If you have 50,000 pages of content, building them all at deploy time (SSG) takes hours. You need a mode that builds only what is necessary or generates pages on-demand.

The server load problem. If every single request hits your API, your server will crash under high traffic. You need caching at the edge (SWR/ISR) to serve cached content without executing server-side logic for every user.

The hydration tax. A complex dashboard page doesn’t need SEO. Rendering it on the server, serializing the state, and then re-running the same JS in the browser (hydration) just wastes CPU cycles. You need a mode that bypasses SSR entirely (SPA/CSR).

The SEO conflict. Dynamic content that changes every second (like stock prices) cannot be static. Yet, you want the initial load to be fast for search engines. You need a mode that provides a cached version for the bot but fetches fresh data for the user.

The operational trade-off. Every rendering mode is a trade-off between build time, server cost, initial load speed, and runtime interactivity. Hybrid rendering exists because no single mode is correct for every page in a modern web application.


a. Universal SSR and the Default Mode

By default, Nuxt uses Universal Rendering. This means every request is handled by the server (or edge worker), which runs your setup functions, fetches data, renders the Vue components to HTML, and sends it to the browser. Once the browser receives the HTML, it “hydrates” the application, attaching event listeners and making it interactive.

// nuxt.config.ts
export default defineNuxtConfig({
  ssr: true, // This is the default
});

This is the “everything” mode. It is great for SEO and initial load speed because the browser gets meaningful content immediately. However, it requires a Node.js server or an Edge function to execute at request time. If your content is static, this is overkill because you are re-generating the same HTML for every user request.


b. SSG and SPA Modes

Static Site Generation (SSG) happens when you run nuxt generate. Nuxt iterates over your routes and renders them into static HTML files at build time. There is no server involved at request time; a CDN or static file host serves the HTML, CSS, and JS.

# Generate the static site
npx nuxi generate

Client-Side Rendering (CSR/SPA) is the opposite of SSR. You disable SSR entirely, meaning the server sends a blank HTML shell, and the browser fetches the data and renders the components.

// nuxt.config.ts
export default defineNuxtConfig({
  ssr: false, // Disables server-side rendering
});

You can also apply this per-route. If you have an admin dashboard that doesn’t need SEO, you can force it to be an SPA while keeping the rest of the site as SSR.

// nuxt.config.ts
export default defineNuxtConfig({
  routeRules: {
    '/admin/**': { ssr: false }, // Only this path is CSR
  },
});

c. Hybrid Rendering with routeRules

The routeRules option is the crown jewel of Nuxt’s rendering architecture. It allows you to cache, redirect, and change rendering modes based on the route pattern. This is where SWR and ISR live.

SWR (Stale-While-Revalidate): The server renders the page, caches it, and serves it to users. When the cache expires, the server serves the stale version while generating a new version in the background.

// nuxt.config.ts
export default defineNuxtConfig({
  routeRules: {
    // Cache the blog index for 60 seconds
    '/blog': { swr: 60 },
  },
});

ISR (Incremental Static Regeneration): This is similar to SWR, but the cache never truly expires in the traditional sense; it regenerates on demand.

// nuxt.config.ts
export default defineNuxtConfig({
  routeRules: {
    // Regenerate the product page after 1 hour (3600 seconds)
    '/products/**': { isr: 3600 },
  },
});

This allows your application to be incredibly fast. Static pages are served instantly from the cache, and the server is only burdened with regeneration periodically, not on every single request.


Complete Example Session

// ============================================
// PART 1: GLOBAL CONFIGURATION
// ============================================
// nuxt.config.ts
export default defineNuxtConfig({
  ssr: true, // Default
});

// ============================================
// PART 2: STATIC GENERATION (PRERENDERING)
// ============================================
// Prerender the home page at build time
export default defineNuxtConfig({
  routeRules: {
    '/': { prerender: true },
  },
});

// ============================================
// PART 3: CLIENT-SIDE RENDERING (SPA)
// ============================================
// Force the dashboard to be CSR only
export default defineNuxtConfig({
  routeRules: {
    '/dashboard/**': { ssr: false },
  },
});

// ============================================
// PART 4: CACHING WITH SWR
// ============================================
// Cache API response for 1 hour
export default defineNuxtConfig({
  routeRules: {
    '/api/data': { swr: 3600 },
  },
});

// ============================================
// PART 5: INCREMENTAL STATIC REGENERATION
// ============================================
// Regenerate static pages periodically
export default defineNuxtConfig({
  routeRules: {
    '/blog/**': { isr: 3600 },
  },
});

// ============================================
// PART 6: REDIRECTS
// ============================================
// Permanent redirect for old SEO links
export default defineNuxtConfig({
  routeRules: {
    '/old-path': { redirect: '/new-path' },
  },
});

// ============================================
// PART 7: COMBINING RULES
// ============================================
// Complex hybrid setup
export default defineNuxtConfig({
  routeRules: {
    '/': { prerender: true },
    '/api/**': { cors: true, headers: { 'cache-control': 'max-age=60' } },
    '/admin/**': { ssr: false },
    '/blog/**': { isr: 600 },
  },
});

// ============================================
// PART 8: CACHE CONTROL HEADERS
// ============================================
// Manual header injection
export default defineNuxtConfig({
  routeRules: {
    '/static-assets/**': { headers: { 'cache-control': 'public, max-age=31536000' } },
  },
});

// ============================================
// PART 9: CORS PREFLIGHT
// ============================================
// Allow CORS for API routes
export default defineNuxtConfig({
  routeRules: {
    '/api/v1/**': { cors: true },
  },
});

// ============================================
// PART 10: DISABLING SSR FOR A SPECIFIC COMPONENT
// ============================================
// Inside a page component
<template>
  <ClientOnly>
    <ExpensiveDashboardComponent />
  </ClientOnly>
</template>

The example session demonstrated the syntax for routeRules, ranging from basic static generation and CSR enforcement to advanced caching strategies like SWR and ISR, as well as utility rules like redirects and CORS.


Quick Reference

Rendering Mode Options

RuleDescription
ssr: trueUniversal rendering (default)
ssr: falseClient-side only (SPA)
prerender: trueGenerated at build time
swr: <seconds>Cache, then serve stale/revalidate
isr: <seconds>Incremental Static Regeneration

Utility Rules

RuleDescription
redirectPermanent or temporary redirect
corsEnable CORS headers
headersInject custom response headers
cacheControl browser/CDN caching

Performance Comparison

ModeBuild TimeServer LoadFirst Paint
SSGHighNoneInstant
SSRLowHighMedium
SWR/ISRLowLowInstant/Medium
SPALowNoneSlow

Best Practices

โœ… Do This:

// Prerender the home page for speed
'/': { prerender: true },                                      // โœ…

// Use ISR for heavy but infrequent content
'/blog/**': { isr: 3600 },                                      // โœ…

// Use SPA for authenticated dashboards
'/dashboard/**': { ssr: false },                               // โœ…

// Set reasonable TTLs for cache
'/api/feed': { swr: 300 },                                     // โœ…

// Redirect old routes to preserve SEO
'/old': { redirect: '/new' },                                  // โœ…

โŒ Don’t Do This:

// Prerender pages that depend on the request
'/user-profile': { prerender: true },                          // โŒ (will be identical for all)

// Set SWR to 0 seconds
'/api': { swr: 0 },                                            // โŒ

// Use SPA for SEO-critical pages
'/marketing-page': { ssr: false },                             // โŒ

// Overuse ISR for rapidly changing data
'/stock-ticker': { isr: 60 },                                  // โŒ

// Forget to handle dynamic params in ISR
'/products/**': { isr: 3600 },                                 // โŒ (ensure patterns match)

Common Pitfalls

PitfallWhy It HappensFix
Hydration mismatchSSR and Client render different HTMLonMounted or ClientOnly
Build time hangsPrerendering too many routesUse nitro.prerender.crawlLinks
Stale data foreverCache TTL too highLower TTL or use swr
Blank page in SPAJS failed to loadEnsure correct ssr: false usage
404s on dynamic routesRoute not pre-generatedConfigure nitro.prerender.routes

Real-World Examples

1. Blog posts with ISR

routeRules: { '/posts/**': { isr: 3600 } }

2. Marketing landing page (SSG)

routeRules: { '/landing': { prerender: true } }

3. User dashboard (SPA)

routeRules: { '/app/**': { ssr: false } }

4. API endpoint caching

routeRules: { '/api/weather': { swr: 60 } }

5. Redirecting old URLs

routeRules: { '/docs/v1/**': { redirect: '/docs/v2/**' } }

6. CORS for external clients

routeRules: { '/api/public/**': { cors: true } }

7. Setting security headers

routeRules: { '/**': { headers: { 'X-Frame-Options': 'DENY' } } }

8. Prerendering specific dynamic routes

nitro: { prerender: { routes: ['/product/1', '/product/2'] } }

9. Disabling SSR for a plugin-heavy page

routeRules: { '/map-view': { ssr: false } }

10. Forcing SSR for a specific route

routeRules: { '/ssr-only': { ssr: true } }

Visual

Rendering Pipeline

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  RENDERING PATHS                             โ”‚
โ”‚                                              โ”‚
โ”‚  SSR:  User โ”€โ”€โ–บ Server โ”€โ”€โ–บ HTML โ”€โ”€โ–บ Browser  โ”‚
โ”‚                                              โ”‚
โ”‚  SSG:  Build โ”€โ”€โ–บ Static File โ”€โ”€โ–บ Browser     โ”‚
โ”‚                                              โ”‚
โ”‚  SPA:  User โ”€โ”€โ–บ Blank HTML โ”€โ”€โ–บ JS โ”€โ”€โ–บ Render โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

ISR/SWR Mechanism

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  CACHING LOGIC                               โ”‚
โ”‚                                              โ”‚
โ”‚  1. Request โ”€โ”€โ–บ Cache Hit? โ”€โ”€โ–บ Yes: Return   โ”‚
โ”‚  2. Cache Miss? โ”€โ”€โ–บ Render โ”€โ”€โ–บ Save Cache    โ”‚
โ”‚  3. Stale? โ”€โ”€โ–บ Return Stale โ”€โ”€โ–บ Revalidate   โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

routeRules Decision Tree

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  CONFIGURING routeRules                      โ”‚
โ”‚                                              โ”‚
โ”‚  Is it SEO critical?                         โ”‚
โ”‚  โ”œโ”€ No โ”€โ”€โ–บ ssr: false (SPA)                  โ”‚
โ”‚  โ””โ”€ Yes โ”€โ”€โ–บ Is it static content?            โ”‚
โ”‚             โ”œโ”€ Yes โ”€โ”€โ–บ prerender: true       โ”‚
โ”‚             โ””โ”€ No โ”€โ”€โ–บ Needs caching?         โ”‚
โ”‚                        โ”œโ”€ Yes โ”€โ”€โ–บ swr/isr    โ”‚
โ”‚                        โ””โ”€ No โ”€โ”€โ–บ SSR         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
Universal Renderingssr: true
Build-timeprerender: true
Client-onlyssr: false
Stale-While-Revalidateswr: <seconds>
Incremental Staticisr: <seconds>
Configurationnuxt.config.ts
GranularityPath pattern matching

Key takeaways:

  • Nuxt rendering is hybrid. You do not need to choose one strategy for the entire site; you can define the strategy per route using routeRules in nuxt.config.ts.
  • SSR is the default. Universal SSR provides the best SEO and initial load time but requires server execution at request time.
  • SSG is best for performance. Prerendering (prerender: true) generates static files at build time, eliminating server cost for those routes.
  • SPA mode is for dashboards. Disabling SSR (ssr: false) is ideal for authenticated, private areas where SEO is irrelevant and component interactivity is high.
  • SWR and ISR scale your site. These rules cache content at the edge, serving static-like speeds for dynamic content while handling revalidation in the background.
  • Route matching is powerful. Use pattern matching (e.g., /blog/**) to apply rules to entire sections of your application in one line.

Remember: The power of Nuxt lies in its ability to adapt to the specific needs of each page in your application. By utilizing routeRules, you can combine the SEO benefits of SSR, the speed of SSG, and the interactivity of SPA, ensuring that your application is optimized for both the search engine bot and the end user, without the operational burden of managing separate infrastructures for each rendering mode.

Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!