A Blog

By Gene Jones

Dynamic Static Sites with JS

OK, so static sites have disadvantages.

Specifically, my site design is even sparser than the standard static site - usually they use something like Jekyll to generate the site, from a dynamic number of blog posts, etc. The generator turns all this dynamicism into static HTML. That's very powerful. I didn't go this route for reasons dicussed elsewhere.

This leftme with a problem: was I really going to update the HTML for my Archives page everytime I added a post in two locations? And also update the homepage under "recent articles"?

Thankfully, I had experience with templating from Django and, more recently, HandlebarsJS. Templates are, if done properly, elegantly beautiful. They seperate the display logic from the model logic, and elegantly.

By using HandlebarsJS, the client creates the dynamically generated assets. That frees the burden from my server doing it on the fly (e.g. CGI) or doing this ahead of time (static generator).

Now I could update a single location (JSON) and changes would flow out to the rest of my site.

The same advantage a dynamic site, or even a dynamically generated static site, would have is now mine. In this sense, I call this a dynamic static site. It is completly static from a file perspective. It also has no generators. But, some presentation logic is dynamically generated on the user's computer as needed.

It works for a site with small traffic, created by one man. On a large traffic site this would be unfair to the users - the sum of user compute time to generate the dynamic content would far exceed the time for a server to generate the dynamic content and then cache it. $$\sum_{n=1}^{100,000} 5 > 1 * CacheOperation * \sum_{n=1}^{100,000} CacheRetrieval $$