---
title: 'A guide to Nuxt server components'
date: '2023-07-24T22:00:00.000Z'
tags:
- nuxt
- server components
description: It's possible to use server components within Nuxt, even if you are generating a static site. Here's how.
---
'Server components' are becoming increasingly common in the web development ecosystem, for good reason.
Traditionally, in a single-page application, even a server-rendered one, the server is only relevant for the _first_ load, after which the client takes over. That has meant that _every_ part of a web app must be capable of being rendered on both client and server. Alternatively, people have opted for multi-page apps, or MPAs, with the cost this brings in user experience.
But this is not always desirable.
Instead, server components allow server-rendering individual components within your client-side apps.
It's possible to use server components within [Nuxt](https://nuxt.com/), even if you are generating a static site. That makes it possible to build complex sites that mix dynamic components, server-rendered HTML and even static chunks of markup.
## Key benefits
1. โก๏ธ Server components allow you to extract logic **out of your client-side bundle**.
By moving code into server components, these components (and the components _they_ use) no longer need to by hydrated or 'tracked' by Vue. This is particularly useful for complex or expensive operations that probably don't need to be 'rerun' on the client, like applying a syntax highlighter or parsing markdown.
In most cases, using server components in your Nuxt site won't be a magic bullet. Rather, it will be a useful option when there is an disproportionate amount of code needed to render a component on the client.
1. ๐ Server components ensure that **privileged code runs securely**.
When your logic requires access to a database or needs a private key or secret, server components can be a useful solution. They are one way of separating your concerns. (Though note that other **good** alternatives exist, like moving your server-only code into a Nitro server route that is 'fetched' by your component.)
1. ๐ฆ Server components **don't necessarily require a server at runtime**.
By default, Nuxt will prerender any server components used in your application. As long as you've crawled every page of your site, and don't load them only on the client, or change the props at runtime, server components should work just as well on a fully static website.
This means you can use server components on **static hosting** - no need to update to serverless/edge rendering in order to benefit.
> โก๏ธ Plus, if you have enabled payload extraction (which is enabled by default in generated/static sites, and can also be enabled for hybrid deployments), then Nuxt will even prefetch server components used in pages you might navigate to, so they will load instantly.
1. ๐ Server components **are interchangeable with normal components**.
Server components/islands can support all the features of normal components, including shared state, access to the current route, and more. Because they behave just like normal components, you can nest them within server components or just sprinkle them through the rest of your code.
By default, all your plugins will run when rendering server components, unless (coming soon) they are explicitly disabled by setting `island: false` when defining your component.
## Similar but different
There are a other similar-sounding terms floating around that are worth mentioning:
- **React server components (or RSCs)**. This is an entirely different approach to rendering server components which is often linked to streaming responses from server to client.
- **'Island' architecture**: named by [Katie Sylor-Miller](https://sylormiller.com/) and popularised most recently by frameworks like [รฎles](https://iles.pages.dev/) or [Astro](https://astro.build/), this is an architecture which embeds dynamic 'islands' within more static surroundings. The Nuxt approach is the opposite - we embed static 'islands' within a dynamic Nuxt app.
## Using server components
So, how do you use a server component?
First, you'll need to enable the feature (which is still experimental):