Vue.js course Β· Module 15: TypeScript & Nuxt

SSR Concepts: SPA vs SSR vs SSG vs ISR

3 min read Β·
In this lesson6

The NOVA LAB Command Center must deliver information as quickly as possible. Different rendering strategies are like different communication systems on the station - each has its advantages depending on the situation.

SPA - Single Page Application

A traditional Vue application is an SPA (Single Page Application):

  1. The browser downloads an empty HTML file
  2. It loads the JavaScript (Vue bundle)
  3. JavaScript renders the entire page in the browser
  4. Navigation happens without page reloads
Server β†’ [empty HTML + JS bundle] β†’ Browser β†’ [rendering]

SPA Advantages:

  • Smooth navigation without reloads
  • Rich interactivity
  • Simple hosting (static files)

SPA Disadvantages:

  • Slow initial load (large JS bundle)
  • Empty page until JS loads
  • Poor SEO - bots see empty HTML

SSR - Server-Side Rendering

SSR renders the page on the server and sends ready HTML:

  1. The server receives a request
  2. Vue renders the component on the server to HTML
  3. It sends the ready HTML to the browser
  4. The browser displays the page immediately
  5. JavaScript is loaded and "hydrates" the page (adds interactivity)
Request β†’ Server [renders HTML] β†’ Browser [displays + hydration]

SSR Advantages:

  • Faster First Contentful Paint (FCP)
  • Excellent SEO - bots see full HTML
  • Better performance on slow devices

SSR Disadvantages:

  • Higher server load
  • Longer Time to Interactive (TTI)
  • More complex infrastructure

SSG - Static Site Generation

SSG generates HTML at build time:

  1. During npm run build - each page is prerendered to HTML
  2. HTML files are ready to be served
  3. No server needed - plain static hosting
  4. JavaScript hydrates the page on the client
Build time β†’ [generates HTML] β†’ Deploy β†’ CDN β†’ Browser

SSG Advantages:

  • Fastest possible response (files from CDN)
  • No server - cheapest option
  • Excellent SEO

SSG Disadvantages:

  • Content doesn't change between builds
  • Every change requires a rebuild
  • Not suitable for dynamic data

ISR - Incremental Static Regeneration

ISR combines SSG and SSR - pages are generated statically but can refresh:

  1. First visit - page served from static cache
  2. After a set time - the page is regenerated in the background
  3. Next visit gets the updated version
Request β†’ [cache/CDN] β†’ if stale β†’ regenerate in background β†’ new version

ISR Advantages:

  • SSG speed + SSR freshness
  • Automatic refreshing

ISR Disadvantages:

  • More complex configuration
  • Data may be momentarily outdated (stale-while-revalidate)

Hydration - the Key to Interactivity

Hydration is the process where Vue "takes over" the static HTML generated by the server and adds interactivity to it:

Server: <button>Click</button>  ← static HTML
   ↓ hydration
Client: <button @click="handler">Click</button>  ← interactive

Vue compares the virtual DOM with the existing HTML and attaches event handlers, refs, and reactivity - without re-rendering the entire DOM.

When to Use Which Strategy?

StrategyUse when...
SPAThe app requires rich interactivity (dashboard, editor)
SSRSEO matters + dynamic data (store, blog with comments)
SSGContent changes rarely (documentation, landing page)
ISRContent changes, but not in real time (blog, catalog)
Code for this lesson: App.vue
<script setup lang="ts">
import { ref } from 'vue'

type RenderStrategy = 'SPA' | 'SSR' | 'SSG' | 'ISR'

interface StrategyInfo {
  name: RenderStrategy
  fullName: string
  description: string
  pros: string[]
  cons: string[]
  useCase: string
  color: string
}

const strategies = ref<StrategyInfo[]>([
  {
    name: 'SPA',
    fullName: 'Single Page Application',
    description: 'Rendering in the browser after JS loads',
    pros: ['Smooth navigation', 'Rich interactivity', 'Simple hosting'],
    cons: ['Slow loading', 'Weak SEO', 'Empty HTML'],
    useCase: 'Dashboard, editor, internal application',
    color: '#00b4d8'
  },
  {
    name: 'SSR',
    fullName: 'Server-Side Rendering',
    description: 'The server renders HTML and sends a ready page',
    pros: ['Fast FCP', 'Excellent SEO', 'Better performance'],
    cons: ['Server load', 'Longer TTI', 'Complex infrastructure'],
    useCase: 'Store, blog, social media',
    color: '#00ff88'
  },
  {
    name: 'SSG',
    fullName: 'Static Site Generation',
    description: 'HTML generated at build time (build)',
    pros: ['Fastest response', 'No server', 'Excellent SEO'],
    cons: ['Static content', 'Rebuild on change', 'Not for dynamic data'],
    useCase: 'Documentation, landing page, portfolio',
    color: '#9b59b6'
  },
  {
    name: 'ISR',
    fullName: 'Incremental Static Regeneration',
    description: 'Static pages refreshed in the background',
    pros: ['SSG speed + SSR freshness', 'Automatic refresh'],
    cons: ['Complex configuration', 'Temporarily stale data'],
    useCase: 'Blog, catalog, company website',
    color: '#f39c12'
  }
])

const selected = ref<RenderStrategy>('SPA')

const current = ref<StrategyInfo>(strategies.value[0])

function selectStrategy(name: RenderStrategy) {
  selected.value = name
  current.value = strategies.value.find(s => s.name === name)!
}
</script>

<template>
  <div class="nova-lab">
    <h1>Rendering Strategies</h1>

    <div class="tabs">
      <button
        v-for="s in strategies"
        :key="s.name"
        @click="selectStrategy(s.name)"
        :class="{ active: selected === s.name }"
        :style="{ borderColor: s.color }"
      >
        {{ s.name }}
      </button>
    </div>

    <div class="detail" :style="{ borderColor: current.color }">
      <h2 :style="{ color: current.color }">{{ current.name }}</h2>
      <p class="fullname">{{ current.fullName }}</p>
      <p class="desc">{{ current.description }}</p>

      <div class="lists">
        <div>
          <h4 style="color: #00ff88">Pros</h4>
          <ul>
            <li v-for="pro in current.pros" :key="pro">{{ pro }}</li>
          </ul>
        </div>
        <div>
          <h4 style="color: #e74c3c">Cons</h4>
          <ul>
            <li v-for="con in current.cons" :key="con">{{ con }}</li>
          </ul>
        </div>
      </div>

      <div class="use-case">
        <strong>Use case:</strong> {{ current.useCase }}
      </div>
    </div>
  </div>
</template>

<style scoped>
.nova-lab {
  background: #0a0e27;
  color: #00ff88;
  min-height: 100vh;
  padding: 20px;
  font-family: monospace;
}
h1 { color: #00ff88; margin-bottom: 15px; }
h2 { margin-bottom: 4px; }
.tabs { display: flex; gap: 8px; margin-bottom: 15px; }
.tabs button {
  background: rgba(0,180,216,0.1);
  color: #ccc;
  border: 2px solid #333;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-family: monospace;
  font-weight: bold;
}
.tabs button.active {
  background: rgba(0,180,216,0.25);
  color: white;
}
.detail {
  background: rgba(0,180,216,0.06);
  border: 2px solid #00b4d8;
  padding: 20px;
  border-radius: 12px;
}
.fullname { color: #888; font-size: 13px; margin-bottom: 8px; }
.desc { color: #ccc; margin-bottom: 12px; }
.lists { display: flex; gap: 20px; margin-bottom: 12px; }
.lists ul { list-style: none; padding: 0; }
.lists li { padding: 3px 0; font-size: 13px; color: #ccc; }
.lists li::before { content: '> '; color: #00b4d8; }
h4 { margin-bottom: 6px; }
.use-case {
  background: rgba(0,255,136,0.08);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  color: #00b4d8;
}
</style>

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. What does SSR (Server-Side Rendering) mean?

  2. 2. What is hydration in the context of SSR?

These are 2 of 3 questions for this lesson. Solve the rest in the game.

Hands-on tasks in the game

  • Code editor

    Define a RenderStrategy union type and a StrategyInfo interface.

  • Vertical ordering

    Arrange the steps of the Server-Side Rendering process:

  • Code editor

    Define a CrewMember interface and type the data, pending, error states.

  • Vertical ordering

    Arrange the loading order in a SPA (Single Page Application):

  • Click in order

    Arrange rendering strategies from fastest to slowest First Contentful Paint:

  • Code editor

    Define a Page union type and type navigation between pages.

  1. Coding taskPractice: Rendering Strategies
  2. QuestionSSR Definition
  3. Put in orderSSR Process
  4. QuestionHydration in SSR
  5. Coding taskPractice: useFetch Pattern
  6. Put in orderSPA - Loading Order
  7. QuestionSSG vs SSR
  8. Click in orderFCP Speed by Strategy
  9. Coding taskPractice: File-based Routing

Useful articles