A static site generator is, by contrast, quite different. They take a well-known file and directory structure containing site content and page templates, along with a configuration, and generate a static website from that information.
There is, often, no database interaction requiring aggressive caching. There isn’t a user login system that can be hacked by a malicious actor. And, if the site is hacked it need only be regenerated and redeployed to fix the issue. The entire installation doesn’t need to be rebuilt.
That said, depending on the SSG that you choose, the line between them and a CMS can become a little blurred – especially when you integrate tools such as Spinal CMS. But, in principle that is how they work, and we’re going to avoid talking about such tools in this tutorial.
Why would you use a Static Site Generator over a CMS?
If you’re mainly familiar with a CMS, it might seem strange to use anything else – especially a system that requires a lot more direct involvement, and knowledge of HTML and CSS. However, it’s worth bearing in mind that CMS functionality doesn’t come without cost.
A CMS often has a notable amount of overhead owing to interacting with a database to store and retrieve the site information (though that can be reduced through appropriate caching). In addition, A CMS needs to be properly secured and hardened, otherwise it may end up being hacked by one or more malicious actors.
Given these, and other, needs a skilled systems administrator or DevOps professional may be required to install, maintain, and secure them, adding to the lifetime cost of the project.
A static site generator, on the other hand, can be a far simpler solution. Sites generated with them can be deployed on any hosting service, such as Verpex, without requiring special hosting requirements or dynamic language runtimes.
To get them deployed, a basic configuration of one of the common web servers (such as NGINX, Apache, Lighttpd, or Caddy), plus sufficient disk space is all that’s required. For the more technically proficient, the static files could be stored in an S3 bucket or in Google Cloud. Because of that, sites built with an SSG can often scale quicker and with fewer hardware requirements.
However, it’s not all benefits and no downsides. Static site generators do require knowledge of a number of file formats including HTML and CSS, and likely several others, such as Markdown, YAML, TOML, and Mustache or Handlebars templates.
For example, content for a number of static site generators is made up of a combination of Markdown with YAML frontmatter, as in the example below.
---
title: My First Post
summary: Welcome to my blog
date: 2022-08-05
slug: /my-first-post/
categories:
- Blog
tags:
- Hello World
- Introduction
draft: false
---
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tincidunt hendrerit lacus vel laoreet. Vivamus sagittis ante elit, in pharetra urna semper in. Curabitur volutpat blandit ex, in pellentesque quam maximus ac. Morbi aliquet id enim a finibus. Sed varius leo ut nisl lobortis finibus. Suspendisse potenti. Integer id leo id orci rhoncus viverra. Duis convallis posuere urna ornare dapibus. Vestibulum mattis, sem sit amet tristique maximus, turpis magna gravida nibh, ac tincidunt justo neque eget tellus.
In this example, the YAML frontmatter, located between the triple hyphens, provides the page or post metadata, such as when the post is to be published, its taxonomy information, title, and slug. The content located after the YAML frontmatter is the page or post’s content in Markdown format.
In addition, depending on the static site generator chosen, some knowledge of software development may also be required. For example, when using Hugo, to get the most out of its templating system, the user needs to be familiar with (or willing to learn about) Go Templates. The same is true for other generators. Sculpin requires knowledge of PHP, and Jekyll requires knowledge of Ruby.
In addition, you will need to be familiar with the command line, or be willing to become so. This is because you, or someone on your team, will need to learn the generator’s tooling to perform the various tasks to build and maintain the site. For example, Hugo provides the ability to generate a new site, new site content, list existing site content, and publish a site.
Finally, you may also be required to learn Git to gain the full deployment advantages, so that sites can be maintained and deployed as seamlessly as possible. Given these requirements, just because static site generators have far less overhead, they’re not the best choice for every team, nor every project.
What Are the Best Static Site Generators? Top 6
If you do a search for “static site generator”, you’ll find far more than you likely expect to. So, here’s a short review of the top six.
1. Gatsby