digital imprint of David Miller

Can you hear the Static?

I've been thinking a lot about static site generators lately. Full disclosure: I've never used one on a live project. But I'm falling in love with the idea. I thought I'd write some things down so I don't forget them.

I use Wordpress on a lot of client projects, and in many ways I love it. It's quick to set up, and strikes a good balance between complexity and flexibility out of the box. The dashboard has proven simple enough for clients to learn quickly, and as a platform, I think it's really gone from strength to strength over the last couple of years. But it's doing something wrong…

If websites were people, asking a Wordpress site for a page would be a bit like asking somebody to pass the salt while they're sitting on the bus.

For the sake of making a relatively infrequent process easy and accessible (content creation/updating), we add complexity to a massively frequent process (content requests). It's a sad website where updates & content changes outnumber content requests! We get the luxury of a rich ecosystem of content management tools and plugins, but at a price. For these comforts, we ask our servers to do a bunch of repeat computation every time somebody wants to look at what we've made. Each time a visitor requests a page we have a database operation, some php processing to put that data into a template, URL rewrites. It all adds up. And most strikingly to me, we're making the computers do the same thing over and over again. The result of a given Wordpress page query will always be the same, until somebody makes a content change.

Of course this isn't the whole story. Wordpress caching is in really good place. We can make our Wordpress sites run really quite quickly. But this seems like a backwards way of addressing the issue. Even a WP site with the perfect caching set up generates a warren of rewrites and internal server redirects, all of which unnecessary processor ticks that will *always* be the same for a given page request.

Static sites are just faster. This one survived a front page Reddit hug, and I'm sure they did it without buying in extra CPU time. Static sites simply demand less of their servers. Ask it for a file? it gives you that file. If websites were people, asking a Wordpress site for a page would be a bit like asking somebody to pass the salt while they're sitting on the bus. It'll going to take a minute for them to figure out what you mean. A static site is already sitting at the dining table. 

Using a static site does imply some changes to the way we do things though. On the positive side, we can use less powerful hardware to run higher traffic sites at much lower cost. However, we end up having to offload those small parts of our sites that aren't static (and they are usually small, embedded twitter feeds, comments, calendars, maps)  to other services or APIs that we load in asynchronously. This is not a big trade-off — we already do this for many of these elements, and have for years. 

The major change/question is how we do content management. content management is a *really* good thing. We like it enough to spend a lot of money on processor time to pull thousands of fragments of static content out of relational databases and arrange it into pages. We do this all this for the dashboard.  

There are great static site generators out there in the wild right now. Jeckyll is probably the best known, and there are others. But they aren't ready for my clients. They don't have the dashboard. 

The next generation of static site generators need to present Wordpress-style admin interfaces for content creation, updates, and management. And they need to play nicely with asynchronous modules for loading non-static content like comment feeds. 

We have all the necessary ingredients to make this work right now:

Content in databases, A huge ecosystem of HTML templating languages, scripting languages that execute fast enough to give users in-browser previews of what they're working on, accessible server-side scripting languages that can do the actual site-generation. And with products like popping up, we have options for the dashboard.

Let's get together and get lazy. Let's generate our pages when we create or update them, not every time they get requested.