Compressing HTML in Jekyll without a plugin

For a couple of years this site has been hosted on the excellent Squarespace, but it has always been on my to-do list to create something simple and static. Last week I took the plunge and everything is now up and running using Jekyll hosted on GitHub Pages.

I was keen on keeping the site as lightweight as possible, but I assumed some performance tweaks like minifying html would be impossible without plugins (which don’t work on GitHub hosted sites).

That changed when I stumbled across jekyll-compress-html, a jekyll layout that minifies HTML using pure Liquid, which means it works perfectly when building on GitHub Pages.

Using it is dead simple, simply download compress.html, save it in _layouts, and update your base layouts to reference it:

---
layout: compress
---

The compression behaviour is configured in _config.yml. The full set of options are detailed in the documentation, but mine looks like this: