Most websites today fall into two categories - dynamic sites and static sites:
Dynamic sites are interactive, and the user experience can be tailored to the visitor. These are the ones that might remember who you are across visits or deliver content that's most applicable to the region you're visiting from. They rely on a content management system (CMS) or database for rendering and can continue to grow in complexity as the organization's needs grow.
What is a static site generator?
Benefits of using a static site generator
Static sites' advantages include speed, security, and SEO. They're also easy to maintain and highly scalable. Because the static site generators store an already-compiled page on a CDN, they load a lot faster.
As static site generators are comprised solely of static files, no database is required, resulting in many additional benefits:
There is no need to spend valuable time querying the database or running any resource-intensive server-side scripts.
There are no extraneous libraries, no databases, or other features that a dynamic generator is built with. All you have are static files. Therefore, it’s very simple to work with and migrate as needed.
There’s no database for would-be hackers to attack.
Since there is no need for scripts to run on a file-based generator, scaling is very easy without overwhelming your server.
All static site generators can be exciting and fun, but some require time and effort on configurations, detailed templating, or management tweaks. My team and I joke that I am one of the top blog-less SSG experts, so in this blog post, I’ll walk you through a toolkit for evaluating your project and then share some SSGs that deploy to GitLab Pages.
Here are the SSGs I'll review in this post:
- Hugo is written in Go with support for multi-language sites and complex content strategy.
- Zola is written in Rust with a single binary, no dependencies, and flexible features like Sass compilation.
- Jekyll is written in Ruby, built for blogging, and has a large collection of plugins and themes.
- Hexo is Node.js based with support for multiple templating engines, integrations with NPM packages, and one command deployment.
- GatsbyJS is React-based, works with any CMS, API, or database, and can be used for building headless experiences.
An Evaluation Toolkit
With so many static site generators available, selecting one for your project can be overwhelming. When evaluating which SSG is right for you, here are a few things to consider about your project, use case, and the type of work you're looking to put into the site.
Identify the use case
It’s important to understand your site's needs, purpose, and content. Are you building a personal blog, a landing page for a product, or documentation for a tech project? Consider whether you need a streamlined editor experience, content, and interactions with your user. The better you can identify the experience you'd like your visitors to have, the easier it will be to pick the feature set that can best support it.
Specify languages and frameworks
There are so many static site generators out there that you can find one in nearly every language and framework. Consider whether you want to learn a new language or use something you're familiar with. Depending on how much time you’d like to invest in setting up, you should also review the installation details and see if you’re familiar with the templating language, dependencies, and theming layer.
Review the ecosystem
Check out the community
There are often Discord or forum communities where you can get support, share ideas, review cases studies, and see what other people are building. Some of the most popular generators might even have conferences or workshops for getting started on more complex topics.
Identify the specialty
From microblogging to academic portfolios and small business sites, static site generators cover various use cases for different people. Each SSG has its own thing, whether it’s the framework it uses, a unique feature in its templating language, or the size of the installation binary.
The Single Binary Approach
Some static site generators install a single binary and don't require complex dependency management. The single binary approach gets things set up quickly and easily. It is also easier for non-technical or academic users since you can pass the executable around for installation and use a markup language like Markdown to write content.
Hugo is written in Go, a statically compiled language, with support for multiple platforms. The Hugo binary can be downloaded and run from anywhere and is simple to install, with no runtime dependencies or installation process. Upgrades involve downloading a new binary, and you're all set. Hugo supports unlimited content types, taxonomies, dynamic content driven from an API, multi-lingual sites, and markdown. It also ships with premade templates making it easy to get started with menus and site maps.
One of the advantages of using Hugo is that it doesn't depend on client-side JS. It also has a thriving community with many prebuilt themes and starter repositories. There is an existing sample site in Hugo that deploys to GitLab pages. If you're migrating to Hugo from another SSG, you can use the hugo import command or one of the community-developed migration tools. There's a Hugo site example on GitLab pages to help you get started.
Zola is a strongly opinionated SSG written in Rust that uses the Tera template engine. It's available as a prebuilt binary, is super-fast to set up, and comes with some essential features like syntax highlighting, taxonomies, table of contents, Sass compilation, and hot reloading. The Tera templating engine supports build-in short-codes to inject more complex HTML or for repetitive data-driven sections. Configuration for Zola sites is managed in TOML.
One of the limitations of Zola might be the lack of a built-in scripting language. Unlike other SSGs, there isn't an ecosystem of plugins you can add to your site. Many in the community appreciate this lack of modularity because Zola’s specialty is content-driven sites. One of the most popular posts on their Discourse forum is a proposal for plugins which discusses ways to include dynamic loading for plugins without affecting the single binary distribution.
Zola is commonly used for content-driven websites. One of its notable features is how content is structured using a tree with sections and pages. There is no example site on GitLab pages, but the Zola documentation includes a guide on how to deploy to GitLab pages.
The Standard Approach
When it comes to generators and frameworks, you might hear, "Boring is better." Sometimes the preferred SSG is feature complete, well documented, and has a community of examples and plugins to support it - even if it's not actively growing anymore.
Jekyll is a static site generator written in Ruby and released in 2008. It paved the way for static sites by replacing the need for a database and inspiring developers to start creating blogs and documentation pages quickly and easily. It uses the Liquid templating language, has a vast plugin ecosystem, and is known to be beginner-friendly since it’s just HTML (or Markdown, if you prefer). While it doesn’t provide many features out of the box, Jekyll supports Ruby plugins for any functionality you might need. There are over 200 plugins, themes, and resources available to use.
One of the challenges when working with Jekyll can be the requirement of having a whole Ruby development environment to build your site. This can be tricky for developers unfamiliar with Ruby or when making updates. Another thing to consider is the build pipeline - it supports Sass compilation out of the box, but the community recommends using webpack to build assets instead. If you're migrating to Jekyll from another framework or CMS, there are importers that can help automate part of the process. There is a Jekyll site example that deploys to GitLab pages.
Hexo is a NodeJS static site generator that offers itself as a blogging framework. It has built-in support for Markdown, front matter, and tag plugins. It specializes in creating markup-driven blogs. Hexo provides the Nunjucks template engine by default, but you can easily install additional plugins to support alternative templating engines. Like Jekyll, Hexo also supports migrations from several popular frameworks, including WordPress.
A notable feature of Hexo is tag plugins. Tag plugins are snippets of code you can add to your Markdown files without having to write complex or messy HTML to render specific content. Hexo supports several tag plugins, including block quotes, Twitter and Youtube embeds, and code blocks. There’s an example site for Hexo that deploys to GitLab pages and also a guide in the Hexo documentation.
SSGs and beyond
For those who love flexibility and modularity, there are some SSGs that allow you do everything from full content moderation support and dynamic API-driven content to state management and partial rendering.
GatsbyJS is an open-source React-based static site generator optimized for speed and has an extensive plugin library. GatsbyJS supports routing, and handling images, accessibility, and hot reloading out of the box. To improve performance, it loads only the critical elements of the page and prefetches assets for other pages to load them as quickly as possible. It also uses webpack to bundle all of your assets.
GatsbyJS believes in a “content mesh” where third-party platforms provide specialized functionality to the base architecture. It allows you to seamlessly pull data from multiple sources, making it popular for Headless approaches with a CMS backend like Drupal, WordPress, or Contentful. You use GraphQL to query the APIs and manage data throughout your site. The GatsbyJS community has contributed over 2000 plugins, including starter repositories and templates that you can use to get started. There’s an example GatsbyJS site that deploys to GitLab pages.
A notable feature of Astro is partial hydration. If you decide that parts of your site need interactivity, you can “hydrate” just those components when they become visible on the page. This way, your pages will load super fast by default and have “islands of interactivity”. There are several themes, plugins, components, and showcase projects available. Astro has an online playground where you can try out features and integrations in your browser. There’s also an Astro example site on GitLab pages.
Creating your own SSG
Sometimes, the best part of building a static site is creating a custom generator based on a specific programming language, architecture, and feature set. You might find that the process of creating a static site generator is more exciting than actually writing blogs for your site. Consider several preferences, from document structure to a templating language, theming support, custom plugins, and the build pipeline. You’ll have the opportunity to customize the features to your liking. And there are many static site generators that deploy to GitLab pages to provide inspiration!
Cover image by Kelly Sikkema on Unsplash
“Need a new static site generator for your blog? @gitlab’s @sugaroverflow shares a toolkit for evaluating static site generators, their notable features, and limitations.” – Fatima Sarah Khalid
Click to tweet