Why Use a Static Site Generator?

09 Aug 2018 . category: code . Comments

#jekyll #web-dev

Last Updated January 21, 2019

Suppose you want to create a blog. But you don’t want to use one of those drag-and-drop, Word-style, CMS (content management system) programs like Wordpress or Blogger, because first of all you want more control and customization, and second of all you want to program your site, not just design it. You have several options.

You could program the whole site, with a backend, using a framework in some language like python, java, or C - but writing a whole backend and frontend just for a simple blog? You might not want to do that.

Or you could write a 100% static site - but this is obviously not a reality for a blog, because every time you wrote a new post, you’d have to go back and add the links for that post to the archive pages and such. You could do this in a scrape, but it wouldn’t be very flexible.

So, what do you do when you need a fast, simple blog that you can easily customize (in code), and you don’t want to use a CMS or worry about a database, server, and security? One option is to use a static site generator.

A static site generator takes in dynamic code, usually a combination of HTML/CSS/Javascript, some templating language (Jekyll uses Liquid), and some kind of markdown language, and generates a static site with it. So, for example, when you generate your site, you can write templating code for the archive pages that will generate a link for every post in, for example, a posts folder.

The most popular open source static site generator by far is Jekyll. A huge list of sites made with jekyll can be found here. I made this blog with jekyll.

Here are some advantages of using Jekyll or another static site generator:

  • Ease. You want a customizable, static site, but that doesn't mean you want to write every page in raw HTML - Jekyll uses Markdown language to make writing blog posts as easy as writing an email, even for non-programmers.
  • Simplicity. Jekyll is extremely simple - you won't get bogged down in hundreds of settings, dependencies, etc.
  • Speed. Jekyll generates amazingly fast sites because static sites don't need to query databases or render templates - they just return whichever page you request. Because of this, static sites don't crash as often as dynamic sites.
  • Security. Because static sites don't make database queries, they are extremely secure.
  • Easier to Maintain. Static sites don't have servers with databases to maintain, because you can easily, simply host them on services such as github pages or Amazon S3. Because of this, static sites are also much cheaper.

The only major downsides to using static sites are they can’t accept user input/login, because there is no database to store that information. This means no forms, comments, logins, etc. However, you can get around this by using external services like Disqus (for commenting) and Formspree (to create forms).

There is one last major reason why I think Jekkyl is so great (and why I chose to use it): Jekyll is the engine that Github Pages uses. Github Pages is a free hosting service for static sites, and it is really easy to use - up until recently, my site used github pages.

Because github pages already uses jekyll, all you need to do to publish (or update) a Jekyll site to github pages is push your source code to your github repository. and by naming that repo scitronboy.github.io, github automatically serves the site, using Jekyll, to scitronboy.github.io :grinning:

If you’re a programmer looking to quickly create an easy, simple, blog, for free, I highly recommend Jekyll and Github Pages.

ps. I am planning to write a tutorial on creating a jekyll blog sometime in the future.