#static server rendering

1 messages · Page 1 of 1 (latest)

sand sierra
#

Is it possible to use server rendering to generate static html files ?

meager perchBOT
#

Hi @sand sierra. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, it is possible to use server rendering to generate static HTML files in Astro. This is achieved through the configuration of the output setting in your Astro project.

Astro provides two modes for this: server and hybrid.

  • In server mode, your site is server-rendered by default. However, you can opt-in to pre-rendering for any individual page or endpoint. This is done by adding export const prerender = true to any page or route. Here's an example of how to configure your Astro project for server mode:
import { defineConfig } from 'astro/config';
import nodejs from '@astrojs/node';

export default defineConfig({
  output: 'server',
  adapter: nodejs(),
});
  • In hybrid mode, your site is pre-rendered to HTML by default. However, you can opt-out of pre-rendering for any individual page or endpoint by adding export const prerender = false to any files that should be server-rendered. Here's an example of how to configure your Astro project for hybrid mode:
import { defineConfig } from 'astro/config';
import nodejs from '@astrojs/node';

export default defineConfig({
  adapter: nodejs({ mode: 'middleware' // or 'standalone' }),
  output: 'hybrid',
});

For more information, you can refer to the Astro documentation on server-side rendering (https://docs.astro.build/en/guides/server-side-rendering/).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: