#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
5 min read
Question 33 of 37hard

What is Server-Side Rendering in Vue?

SSR concepts and Nuxt.js.

What You'll Learn

  • What is SSR
  • SSR benefits
  • Nuxt.js overview

What is SSR?

Server-Side Rendering renders Vue components on the server and sends HTML to the client.

Benefits

BenefitDescription
SEOSearch engines can crawl content
PerformanceFaster first contentful paint
Social sharingMeta tags available immediately

Basic SSR Flow

code.jsJavaScript
1. RequestServer renders Vue app → HTML
2. Browser receives HTMLShows content
3. Vue hydrates → App becomes interactive

Nuxt.js (Vue SSR Framework)

$ terminalBash
npx nuxi init my-app
cd my-app
npm install
npm run dev

Nuxt Page Example

code.txtVUE
<!-- pages/index.vue -->
<script setup>
const { data } = await useFetch('/api/posts')
</script>

<template>
  <div v-for="post in data" :key="post.id">
    {{ post.title }}
  </div>
</template>

Data Fetching

code.jsJavaScript
// Server-side
const { data } = await useFetch('/api/data')

// Client-side only
const { data } = await useFetch('/api/data', {
  server: false
})