Static site generator pros and cons

4 reasons you should use a static site generator—and 4 reasons you shouldn‘t

Static site generator pros and cons
Adam Patrick Murray/IDG

A long time ago in an Internet far, far away, people built their websites by hand, placing every HTML tag with the loving care of an artisan. They spent the day pondering questions like, “Should I use a <b> or go all the way with a <flash> tag?” 

The first wave of automation to sweep through the server farms swept these tag-slinging humans aside and replaced them with templates that automatically wrapped the words and images in the design of the day. Suddenly the old webpages were said to be “static”—a retronym that showed how dated they were compared to the new, adaptive, and style-forward “dynamic” websites.

Oh how times change. Just as bow ties go in and out of fashion, suddenly “static” is in vogue and the hip coders are discussing it without a hint of sneering condescension. “Static” is zippy and fast. “Dynamic” is pondering, plodding, and slow.

Perhaps someone had time to think while waiting and waiting for the build process to finish transpiling a huge repo filled with an unholy mixture of React, Vue, and Angular? Or maybe someone couldn’t get the database to scale enough to handle the endless queries from the multi-tiered dynamic layer that was constantly pouring the same data into the same blocks on the same pages? Perhaps someone wondered why we were going through all of this trouble just so the webpage could have a little personal greeting in the corner saying, “Bob’s Account”?

The back-to-the-future solution to all of these problems is a static site generator, a tool that is just as complicated as the dynamic sites and pours all of your content into templates in the same way. But it saves the result in a file with the .html suffix, turning the data into static webpages that can be hosted on the same kind of static web server that your grandparents used to host their honeymoon GIFs. You don’t need multi-tiered this or microservice that to connect with the world. You just copy some files and let a basic web server do the work.

There are already a good number of static site generators out there. Jekyll is built for Ruby apps. Next or Gatsby will export React. Many of the dynamic platforms like Drupal have modules that will construct static copies of either the full site or important subsets. There are so many that some developers have built nice curated lists. (See here and here.)

Like all world-changing ideas, this strategy is both a legitimate flash of genius and a tepid mixture of meh, depending on how you look at it. Here are four reasons why static site generators are wonderful interleaved with four just as compelling reasons to yawn.

Pro: Static websites are fast

Say it again in one breath: FAST! The entire webpage is sitting there in an SSD ready to go. The web server only needs to copy it to the TCP/IP code sitting right on top of the network card. There is no need to fetch some tidbit from a database or wait for some library to render a template. Even in the early days of the web, web servers were so fast they could saturate a T1 line with just a low-end Intel 486 CPU and a tiny bit of RAM. The combined cruft of several decades of millions of coders adding yet another layer of indirection has made that only a memory, but the static site generators are a magic ticket back to the days when web servers were fast. Don’t even bother modifying it with an adjective like “extremely” or “awesomesaucily.” Just use the one syllable: fast.

Con: Static websites are stripped down

If it’s fast you want, why don’t you just strip away everything from your webpage? You could make a weather website really fast if you dispensed with all of the radar GIFs and animated storms and replaced all that bling with just one number, the temperature. You could even pack it into one signed byte with values between -127 and 128, at least until global warming gets really bad.

Static websites are faster, but much of this speed comes from stripping away personalizing features and extras. People come to websites for features and information, customized to their needs. They want more than stripped-down standard fare from a one-size-fits-all assembly line.

Pro: Static websites are flexible

Static site generators can run whenever you feel like updating the pages. That may be right away in an emergency, but it can also be overnight or whenever the server time is the cheapest. You can even use one of those discount, preemptable cloud instances like Google offers because if the job pauses several times, it doesn’t matter. You might even let your personal laptop run at night and spend nothing on cloud server time at all.

So many parts of the Internet infrastructure are optimized for doing something right away. Site engineers obsess about the milliseconds spent responding to a message. They fret about how to spread the response calculations over lots of machines running in parallel, all so some ungrateful, no good kid can see a meme and type “LOL.”

Doing the processing offline is so much simpler. If a database call takes a few seconds, it’s no big deal. If somebody wants to use a better algorithm that provides a better answer, you can code that up and not pull your hair out trying to keep data consistent across lots of servers trying to work in parallel. Stop fretting. You’ve got as much time as you need (within reason, of course).

This is the irony of static site generators. Even though the individual webpages are conceptually set in stone, you can spend hours doing a better job with them. The static web life is for the philosophers, the deep thinkers, and the purists who want to construct their webpages the right way, not rush the bits out the door.

Con: Static websites can grow stale

The first sign that a website is abandoned is the copyright notice on the bottom. If it says last year or worse, two or three years ago, you start to think a bit less of the company. This is an extreme example, but dated bits are always a risk with a static website. They don’t serve up the freshest food.

Smart site managers, of course, can fight this by updating the site on January 1st and maybe rolling out some new CSS every few months. They can regenerate everything with newish, updated looks as fast as the designers can tweak the colors.

And, yes, the static site defenders are certainly right that many of the pages never change. If a company has a dynamic mission statement with rapidly changing commitments to this fad or that trend, well, it wouldn’t look too committed. If the facts being delivered aren’t changing, why do we need dynamic web code to restate what should be carved in stone?

Still, it’s hard to get away from the feeling that the static websites are serving up something old and fusty. They’re like the steam tables at the corner deli or the shrink-wrapped sandwich at the newsstand by the last gate in the farthest wing of the airport.

Pro: Static websites can be thrifty

There’s no getting around the fact that static site generators produce lots of pages with lots of repetition. Every part of the website template is repeated in every one of the countless static pages. Good programmers who like to count bytes and fret over efficiency start to have heart palpitations.

But why? Disk space is cheap. As I write this, I’m wondering whether to buy a two terabyte SSD drive that is on sale for $44. As I write this, there are only 47 million pages in the Wikipedia. You can fill that two-terabyte drive with hundreds of static versions of the Wikipedia pages and still have room for lots of cat videos.

These pre-computed static pages are ready to go. Cheap disk space is a gift. Use it.

Con: Static websites can be wasteful

It’s hard to argue with the pre-computed efficiency of several fat drives filled with data that is ready to jump at whatever request comes over the wire. Clearly that can be a great solution for smaller websites.

It’s harder to justify for large websites fronting lots of data. If a pre-computed webpage isn’t requested by anyone, then the time spent building it has been wasted. You started the whole static site generator to save time, but you ended up wasting it.

Many of the large, data-driven websites may be filled with pages that are accessed once every decade at most. How many of those Wikipedia pages are accessed each year? Re-running the static site generator for all of these rarely used pages every time the designer tweaks the look or updates the copyright notice at the bottom can be extremely wasteful. Why not just have a current template and dynamically fill it with the data when someone actually wants to read it?

Pro: Static websites can use AJAX

Just because the webpage itself is as unchanging as the rock of Gibraltar doesn’t mean that it is completely static from top to bottom. A few AJAX calls can download extra bits of data in the background, long after the page is rendered. These calls can add the latest stock prices, the weather forecast, or some personalized details about a user’s account. Just a few bits of data can add quite a bit of life. You don’t even need to go out to the network if you store some of the data locally in cookies or local storage. A quick call can retrieve the user’s name, birthday, or basic account details and give the page a personalized feel.

Con: Static websites lack intelligence

Many dynamic sites are already pretty static. If you look under the hood of websites built on frameworks like Drupal, you’ll find an elaborate and intelligent caching mechanism that stores the current copies of pages when they’re generated. If someone else asks for the page a few seconds later, they get a static version from the cache, not a dynamically generated new version.

The caching algorithms can very smartly cache only unchanging blocks on the page. The cached version can also borrow a trick from the static site playbook and use AJAX and other JavaScript cleverness to update the latest pages.

Static websites and the modern web

Over the years, the web serving world has slowly created content delivery networks, or CDNs, that are localized caches of static content distributed throughout the world. If you go to a big dynamic site, many of the unchanging bits like the logo GIFs are already cached in many local machines near the major hubs. The static content doesn’t clog up the backbone or even many of the smaller tendrils of the Internet. It comes from a caching machine that may be less than a mile away from your browser.

Static site generators can take advantage of these CDNs easily because the CDNs are designed to work with unchanging files. Once you produce the static files, the CDNs will do the rest and deliver them very quickly. The static site generators are the perfect complement.

The solution is to pre-compute as much of your pages as possible so these CDNs can deliver the unchanging data as easily as possible. Then mix in the dynamic information with small, lightweight AJAX calls that don’t block the page rendering. It’s a combination that’s agile and adapted to the modern web infrastructure.

Copyright © 2019 IDG Communications, Inc.