Website Generators
There are some great options for building static websites these days - these are some I've tried.
In recent years, I’ve come to realise that the bulk of websites I’m involved with are entirely or at least mostly static - their content isn’t dynamic, it doesn’t really need a database and a load of code running to produce a page every time a visitor opens a page.
Pre-generating these pages - so the webserver only has to serve up a simple HTML page - has several benefits; not only is it a lot faster, it can be cheaper (because you don’t need as powerful a server)
Cecil
The first site generator I seriously explored was Cecil,
or cecil.phar as I tend to think of it (because it’s distributed as a single
phar - PHP Archive - file).
The fact that it’s PHP based was one of the major things that attracted me to it; PHP is a language I know far too well, and the fact that the templating is all done in Twig - a templating language I’ve used in other PHP projects - made it a bit of a no-brainer.
It’s also very powerful; not only is Twig pretty flexible on it’s own, but it’s fairly simple to add PHP extensions as you go along, in case you find yourself trying to do something the framework doesn’t want you to (trust me, spend any time with static site generators and you’ll find yourself in that spot!)
So I was very happy, until I started pointing it at a blog with close to 500 pages and I discovered it’s Achilles’ heel. Performance. It’s not so much of a problem with deployment - I’ve got that set to happen automagically in the background - when adding new content, having to wait minutes for the whole thing to reprocess gets very tedious, very quickly.
With regret, I walked away from the familiar world of Twig and moved onto the next most recommended option.
Hugo
Probably one of the best known generators, Hugo is - as you may be able to guess from the name, written in Go. Developers do love a good nominative pun.
It describes itself as “the world’s fastest framework”, which may also have been an influence in me trying it after my Cecil experience. And it really is blisteringly fast - although for various reasons I never quite got as far as running the 500 page site on it.
At first glance, it’s great - it does most things you need straight out of the box, is fast and well documented. However, when you’re trying to do something that doesn’t quite fit into the Hugo model, you start hitting rails - while you have some basic scripting, it felt like I spent more and more time fighting with the limitations of the built-in functions to try and get out of it what I needed.
Now, it’s possible that I was doing it all wrong and suffering from learning a framework at the same time as using it in odd ways, but the compile time savings compared to Cecil were getting eroded by the coding time. So I jumped again.
Astro
And so, on to Astro; this one is built in Javascript which is not a language I particularly love (and not one I instinctively associate with performance) but which comes with some considerable benefits.
For a start, because it’s installed through the ‘normal’ Javascript tools (npm
et al) it’s very easy to manage version changes in my deployment scripts, and
keeps the CI stuff simple.
Better than that, ultimately you can have arbitrary Javascript in your layout and components - which means you can code around any limitations the framework presents. It’s not perfect - there are restrictions on what you can do and where - but it’s a whole lot more flexible than Hugo was.
One thing I dislike about Astro is that it keeps wanting to be more than it is; I’ve come to it as a static site generator, and it does that very well, but deep down it wants to be running server side too. For now, it’s possible to keep it in check but it is a minor worry going forward.