Tuesday, March 15, 2016

7 Reasons to Use a Static Site Generator

static site generators

Static site generators have become increasingly popular and, if my prediction is correct, usage will explode during 2016. Let's establish what we mean by the term "static site generator"

What is a Static Site?

Think back to the first website you built. Most developers start by creating a series of pages contained within individual HTML files. Each will call in assets such as images, CSS and perhaps a sprinkling of JavaScript. You possibly launched these files directly from the file system without a web server. Life was simple.

Difficulties arise as your site becomes larger and more complex. Consider navigation: it may be similar in every file, but adding a new page requires updates to every other. Even references to CSS and images can become awkward as folder structures evolve. You may have considered options such as server-side includes or PHP, but an easier option can be a content management system (CMS) …

What is a Content Management System?

A CMS typically provides administrative control panels -- which allow authors to write content that's stored in a back-end database. When a visitor requests a URL, the CMS:

  1. determines which page is required
  2. requests appropriate content from the database
  3. loads an HTML template (normally from the file system)
  4. renders the content within the template, and
  5. returns a formatted HTML page to the visitor's browser.

This occurs almost instantly. The template can include code to generate menus according to the navigation hierarchy. Life is sweet, and more than one in four people choose the PHP/MySQL-powered open source WordPress CMS to manage their website.

Unfortunately, a CMS raises a different set of issues:

  • You need to adhere to the CMS's way of working. It can be awkward to add custom text or components.
  • The server is doing more work, and performance can be affected.
  • There are additional points of failure. A software upgrade or database failure can bring your site down.

What is a Static Site Generator?

An SSG is a compromise between using a hand-coded static site and a full CMS, while retaining the benefits of both. In essence, you generate a static HTML-only website using CMS-like concepts such as templates. The content can be extracted from a database but, more typically, Markdown files are used.

The site generation can occur on your development machine or staging server. The resulting HTML files are then deployed to a live web server. Users will never know the difference.

A related concept is a "Headless" or "Decoupled" CMS. These use an interface such as WordPress to handle content administration but allow other systems to access the data via a REST API. Therefore, an SSG could build a static website using WordPress page content extracted from an internal server. The resulting HTML files can be uploaded to a web server -- but the WordPress installation need never be accessible from outside the organization.

Popular static site generators include Jekyll, Pelican, Hugo and Metalsmith -- see StaticGen for many more. Let's examine the benefits of using one …

Continue reading %7 Reasons to Use a Static Site Generator%


by Craig Buckler via SitePoint

No comments:

Post a Comment