DEV Community

Juho Lehtinen
Juho Lehtinen

Posted on • Originally published at lehtu.github.io

Hosting a Static Website in Github: 2023 edition

During the years of self managing VPS servers and hosting Wordpress I got allergic to all that trouble and struggle. There has been many good options for hosting websites, being that Wordpress or not, but webhotels were always kinda sluggish and free versions especially unreliable and with limited features.

For my hobby projects I liked using Heroku for a good amount of time. It was easy, cheap to free, pure joy. But as we all know that's ruined now.

At work I don't mind using AWS or Azure, maybe even GCP if someone pays enough. On the spare time I don't have the patience for having and using multiple platforms for all my projects. I like it easy, without magic, everything in the same place and if possible for free.

Wordpress, Drupal and many other nightmares made me fall in love with static site generators. I do like Jekyll and Gatsby, but because of the tech stack used at work I prefer NextJS. However, for writing this blog I decided to try something else, something new, something fresh - Eleventy or 11ty.

Github Pages

Github pages has been a good way to host a static website for a long time, but the need to build the site and commit to another branch was always a struggle for me, it felt like I'm doing something wrong, and often I did, because it didn't work as expected. Not to mention always forgetting to put .nojekyll file in the repo.

Okay, it's not ideal but manageable. I just would write my blog or website content locally, build locally and push to Github, then it will update the site from the branch dedicated for the github pages. Still with me? Okay good, let's dive deeper.

Github Actions

Nowadays you can use Github Actions to build and deploy your Github Page. Yes, you read correctly. No need to have dedicated branch for the built version of the static website, no need to build the site locally, no more.

In GH Actions you just need to install your depencies if any, run the build command, build the artifact and deploy to Github Pages, and voilá!

Example Usage

Let's say you have a blog hosted in Github. You need to write a new post and publish it. Now you can just create new file to your project in the Github UI, write your content, commit and Github action will do the rest and boom! Blog updated!

How to get started

I have build and shared a github template, the same as I'm using for this blog, so you are able to get fast start with launching your next blog in github - grab it from here: 11ty-gh-actions-template

Top comments (0)