Over the last couple of years, static site generators have been garnering a lot of attention, particularly among the geek community who have a degree of web development expertise. There are dozens of static site generators, written in almost every programming language you can think of, with the standouts from the crowd being Jekyll, which is written in Ruby, and Pelican, which is similar but written in Python. A new static site generator recently joined the line-up; Hugo, which is written in the relatively new Go programming language.
In this article, I’d like to take a quick look at what a static site generator does, why you might consider using one, and the features that Hugo in particular brings to the table.
Static site generators can best be understood in contrast to dynamic content management systems like WordPress. A WordPress page is built by executing PHP code, which retrieves information from a database and puts together the web page to be sent to browsers. This process happens whenever a page is requested — all pages are generated on the server at the time of the request (unless the site is using caching).
There are a number of benefits to using a static site generator:
- The resulting site is very fast. Because almost no processing occurs before the page is ready to be served, there is no latency introduced by the execution of code or querying of databases.
- Static sites are secure. With a dynamic site generator like WordPress, the code is complex and security vulnerabilities are occasionally introduced. Static sites are pure HTML, CSS, and JS, so they are almost impossible to hack (at the level of the site itself; there may still be vulnerabilities elsewhere in the software stack).
- Low resource use. Static sites are incredibly resource efficient.
- Content can be written in any text editor. The generator will take care of turning it into a publishable page.
Of course, it’s not all rosy. Static site generators can be complex to get to grips with and certainly aren’t as easy to use as WordPress for anyone who doesn’t have at least some web development knowledge.
The Hugo Static Site Generator
The first thing to say about Hugo is that it is blazingly fast. For large websites, Jekyll can take many minutes to generate the site. Hugo boasts that it generates each page in a millisecond, which means it can churn through even very large sites quite quickly. That speed is largely due to Go, the programming language in which Hugo is written.
Adding content to Hugo is fairly straightforward. Simple upload a Markdown file and the site will generate the equivalent HTML ready to be uploaded. Hugo is a lot more than simply a Markdown processor though, and has features that include:
- Easy installation.
- Live change rendering during development.
- Powerful theming and templating.
- Customizable URLs.
- Dynamic menu creation.
- Support for YAML, TOML, and JSON metadata.
- Integrated Disqus support.
If you’ve got some web development chops and want to try out something faster and more fun than the standard WordPress installation, Hugo is definitely worth taking a look at.