How to Build a Website (1/3): Static Page generation with Ruby and Image MagickJul 18, 2017 6:55:25 PM
Suppose you are a programmer and your client, who has some tiny or small business, needs a website to advertise that business.
“Sure”, you say. “No problem!”
Suppose further, that you have a hard time fighting your inner perfectionist. You are always striving to exceed expectations. And thus, you decide to add a dynamic menu, a mobile friendly photo gallery and calendar data from a REST endpoint to the site.
So, static page generation is a really cool way to build simple websites. It gives you all the benefits of a full-blown content management system, while avoiding any unnecessary complexity. A static page generator, is basically a command-line-cms. Based on a set of inputs, the engine transforms those according to a bunch of customizable policies. As long as the inputs and the policies are not changed, the output will not change. It is a pure function, so to say. And outputs of pure functions can safely be cached. There is no need to call the function twice with the same input. The content of a simple website, by my definition, does not change very often. And it does not adapt itself to the viewer. It serves no targeted ads and no breaking news. Hence, for this scenario, static page generation is a perfect fit.