Connect with us


7 Causes to Use a Static Web site Generator – SitePoint

Static web site turbines (SSGs) have grow to be more and more fashionable over the previous decade. This text discusses how your web site may benefit from the developer-friendly construct processes, simpler deployments, improved efficiency, and higher safety supplied by a static web site.

First, let’s set up what we imply by the time period “static web site generator” …

What’s a Static Web site?

Assume again to the primary web site you constructed. Most builders begin by making a sequence of pages contained inside particular person HTML recordsdata. Every will name in belongings akin to pictures, CSS, and maybe a sprinkling of JavaScript. You probably launched these recordsdata instantly from the file system and not using a net server. Life was easy.

Difficulties come up as your web site turns into bigger and extra advanced. Contemplate navigation: it could be comparable in each file, however including a brand new web page requires updates to each different. Even references to CSS and pictures can grow to be awkward as folder constructions evolve. You might have thought of choices akin to server-side consists of or PHP, however a better possibility is usually a content material administration system (CMS) …

What’s a Content material Administration System?

A CMS usually supplies administrative management panels. These permit authors to jot down content material that’s saved in a back-end database. When a customer requests a URL, the CMS:

  1. determines which web page is required
  2. requests acceptable content material from the database
  3. masses an HTML template (usually from the file system)
  4. renders the content material throughout the template, and
  5. returns a formatted HTML web page to the customer’s browser.

This happens virtually immediately. The template can embody code to generate menus in accordance with the navigation hierarchy. Life is nice, and greater than 4 in ten folks select the PHP/MySQL-powered, open-source WordPress CMS to handle their web site.

Sadly, a CMS raises a special set of points:

  • It’s essential adhere to the CMS’s means of working. It may be awkward so as to add customized textual content or elements.
  • The server is doing extra work, and efficiency will be affected.
  • There are extra factors of failure. A software program improve or database failure can carry your web site down.

What’s a Static Web site Generator?

An SSG is a compromise between utilizing a hand-coded static web site and a full CMS, whereas retaining the advantages of each. In essence, you generate a static HTML page-based web site utilizing CMS-like ideas akin to templates. The content material will be extracted from a database, Markdown recordsdata, an API, or any sensible storage location.

The positioning technology can happen in your growth machine, staging server, or utilizing a service to construct when modifications are pushed to the code repository. The ensuing HTML recordsdata and different belongings are then deployed to a stay net server.

The time period “static” doesn’t imply “unchanging”. An SSG builds a web page as soon as, whereas a CMS builds it on every request. The tip result’s an identical and customers won’t ever know the distinction.

A associated idea is a “Headless” or “Decoupled” CMS. These use an interface akin to WordPress to deal with content material administration however permit different techniques to entry the information through a REST API, or a GraphQL API. Due to this fact, an SSG akin to Eleventy can construct a static web site utilizing WordPress web page content material extracted from an inside server. The ensuing HTML recordsdata will be uploaded to an internet server, however the WordPress set up want by no means be publicly accessible from outdoors the group.

The time period Jamstack (JavaScript, APIs, and Markup) can also be utilized in relation to static websites. It refers back to the rise in frameworks, serverless features, and related instruments which generate static recordsdata however permit extra advanced interactivity to be created.

Common static web site turbines embody Jekyll, Eleventy, Gatsby, Hugo, and Metalsmith. SSGs can be found for many languages (see StaticGen for a lot of extra). Frameworks akin to Subsequent.js statically render pages the place doable, but in addition permit the developer to run server-side code when vital.

Let’s look at the advantages of utilizing an SSG …

1. Flexibility

CMSs usually constrain your choices, as a result of they’re tied to a database with particular fields. If you wish to add a Twitter widget to some pages, you’ll usually require a plugin, a shortcode, or some customized performance.

In a static web site, the widget can merely be inserted right into a file instantly or utilizing a partial/snippet. There are few limits, since you’re unshackled by the these imposed by a CMS.

2. Higher Efficiency

Most CMS functions provide built-in or plugin-powered caching techniques to make sure pages are generated and reused when doable. That is efficient, though the overhead of managing, validating, and re-generating cached pages stays.

Static websites can create pre-cached pages which want by no means expire. Recordsdata can be minified previous to deployment to ensure the smallest load and simply deployed through world content material supply networks (CDNs). A static web site will at all times carry out higher than a CMS-powered model utilizing the same template.

3. Fewer Server-side Dependencies

A typical WordPress set up requires:

  • an acceptable working system akin to Ubuntu or CentOS
  • an internet server akin to Apache or NGINX
  • PHP with related extensions and net server configurations
  • MySQL
  • the WordPress utility
  • any vital plugins
  • the theme/template code.

These dependencies have to be put in and managed. WordPress requires much less effort than another functions, however it’s nonetheless doable for a single replace to trigger chaos.

A static web site generator could require simply as many dependencies, however they’ll run on a developer’s PC and will not be deployed to a manufacturing server. An SSG generates client-side HTML recordsdata and related belongings which will be hosted on any net server. There’s nothing else to put in, handle, or preserve.

4. Improved Reliability

A CMS is advanced, with many shifting elements and factors of failure. Run a WordPress web site for any size of time and also you’ll virtually definitely encounter the dreaded “Failed to determine a database connection” error. Unexpected CMS issues can come up from sudden visitors surges, which overload the server, crash the database, or limit energetic connections.

Serving a static web site is much less intensive. In lots of instances, the server simply has to return flat recordsdata so scaling in accordance with visitors demand turns into easy. It’s nonetheless doable to crash an internet server or overload APIs, however it’ll take significantly extra concurrent requests.

5. Superior Safety

There are a number of explanation why somebody could need to assault your web site. Visitors hijacking, rogue promoting, linking, authenticity spoofing, and malware internet hosting all allow an unauthorized person to make financial and/or kudos features.

A CMS opens plenty of assault vectors. The obvious is the login display: it’s solely as safe because the weakest person password. Remember that any web page operating server-side code additionally gives potential exploits — akin to firing spam emails through your contact type. It might not be apparent that somebody has gained entry; the worst culprits need to keep hidden.

A static web site could require little or no server-side performance. Some dangers stay, however they’re hardly ever as problematic:

  • Somebody may achieve entry to a server through SSH or FTP and deface pages or add recordsdata. Nevertheless, it’s often easy to test for modifications (maybe utilizing git standing), wipe the entire web site, and regenerate it once more.
  • APIs referred to as by a static web site are uncovered within the browser and could possibly be exploited in an an identical solution to any server-side code — akin to a type emailer. Good safety practices, CORS, and CSP will assist.

6. Shopper Management Issues

You may spend weeks constructing a lovely CMS theme for the shopper to trash their web site inside minutes of handover! Utilizing a CMS just isn’t essentially straightforward, and it gives appreciable energy to content material editors. You may lock down rights akin to plugin set up, however it gained’t forestall somebody altering fonts, introducing clashing colours, including poor pictures, or corrupting the format.

A static web site will be as restricted or as versatile as you select. When you’re utilizing Markdown or comparable flat recordsdata, editors are much less in a position to make errors or adversely have an effect on web page styling. Some will miss the CMS content material administration panels, however you’ll be able to both:

  1. use their present CMS and cleanse information earlier than technology, or
  2. present less complicated workflows akin to enhancing Git-based recordsdata in StackEdit or

7. Model Management and Testing

Database information is unstable. A CMS permits customers so as to add, delete, or change content material on a whim. Wiping the entire web site is a number of clicks away. You may again up databases however, even when that’s performed frequently, you’re nonetheless prone to lose some information.

A static web site is usually safer. Content material will be saved in:

  • flat recordsdata: they’ll then be model managed utilizing Git or comparable techniques. Outdated content material is retained, and modifications will be undone shortly.
  • non-public databases: information is simply required when the positioning is generated so it needn’t be uncovered on a public server.

Testing additionally turns into simpler as a result of the positioning will be generated and previewed anyplace — even on a shopper’s PC.

With a bit of extra effort, you’ll be able to implement deployment techniques to construct the positioning remotely and replace the stay server when new content material has been pushed to a repository, reviewed, and accredited.

So all is sweet within the static web site world. Or is it? Learn my follow-up publish on 7 Causes NOT to Use a Static Web site Generator.

For a sensible demonstrations of constructing websites with a Static Web site Generator, see:

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *