Rendering Strategies in Astro: SSR and SSG

Get familiar with rendering strategies in Astro, SSG, and SSR and learn how to enable SSR in Astro.

Astro originally started out as an SSGIt stands for static site generation. framework for generating static sites. Over the years, however, it added support for handling SSR. While Astro excels at building static sites, it’s important to understand the distinctions between these two terms. Astro is designed to offer flexibility, supporting both SSR and SSG. We’ll see what each rendering strategy offers and when to use each of them.

Defining the terms

In this lesson, we’ll briefly explore when to use SSR and when to use SSG. We’ll also delve into how to enable SSR in Astro. But, first, let’s define the terms.

SSR involves rendering web pages on the server and then sending the fully rendered page to the client’s browser. This means that when a user requests a page, the server dynamically generates the HTML content and sends it to the client.

SSG, on the other hand, pregenerates HTML files for each page during the build process. This is Astro’s default approach. These static HTML files are then served directly to clients, eliminating the need for SSR during runtime. This results in faster website performance compared to SSR. To summarize, both SSG and SSR are distinct rendering strategies.

Get hands-on with 1400+ tech skills courses.