A static website generator is a set of tools for building static websites based on a set of input files. They apply data and content to templates, and generate a view of a page.
Why use a static site generator?
There are many advantages to building a site using static site generators. Perhaps the most significant of them are:
- Security
- Scale
- Performance
Security
Besides speed and performance, static site generators also solve the security problems that plague CMS-powered sites. Static websites are comprised of solely static files. So they have no database – and since there’s no database, there’s no way for attackers to perform standard hacking attacks like scripting, SQL database injections, or take advantage of server-side database security holes.
In addition, platforms like WordPress, which are used by millions of people all over the globe, have naturally become common targets for malicious attackers. There are literally hundreds of tools that a cybercriminal can easily download and run which attempt to compromise existing WordPress, Drupal and Joomla sites automatically – simply by working through all known vulnerabilities against each CMS system (and its plugins), looking for security holes. As such, site administrators need to keep patching their systems with security updates, constantly playing cat and mouse to ensure they won’t be abused by hackers.
Static sites, by contrast, are practically impossible to hack. There is no code running – when a user requests a page, the server just sends a file for that page – so there are no vulnerabilities to exploit.
Scale
The beauty of a site that has already been generated is that each page is ready to serve without additional server work for each request. It doesn’t require adding more computing power to handle spikes in traffic because we’re not compiling a response for each request on-demand. We did the work earlier. We were able to ensure that everything was correct, as part of our automated build process, and now we simply give the users what they asked for.
This resembles the type of caching traditional architectures often add as a layer in addition to the underlying dynamic infrastructure. But allows us to forgo the complex management of what is cached and what needs updating based lots of different parameters. With a pre-built site, everything is able to be cached in the CDN and served directly. The architecture is optimized for scale by default.
Performance
When we make our sites with a static site generator, visitors don’t need to interact with any of the machinery involved in generating each view at all! We can deliver the result of all that prior work directly from a distributed network of caches (a CDN), making the distance that the requests travel short, and totally avoiding interacting with any of the systems.
Performance can soar. And the headaches of planning and budgeting for infrastructure needed to maintain that performance during planned (and unplanned!) traffic levels goes away.
List of some static site generators
- Gatsby
- Next.js
- Nuxt.js
- Hugo
- Jekyll
Gatsby
Gatsby has really made a name for itself over the past couple of years, having successfully secured multiple rounds of funding.
The thing that makes us most excited about Gatsby is the plugin ecosystem. For almost every problem we usually find a plugin to help.
Next.js
Next.js is another amazing option that is built on top of React. It is also extremely popular in the community and basically the other de facto Static Site Generator that uses React.
Although we are listing it as a Static Site Generator, it is important to note that that is not all it is. Next.js first and foremost supports server rendering. You also can define serverless functions as API endpoints. This gives you lots of control over how you build and deploy your Next.js applications.
Nuxt.js
Nuxt.js is a library for Vue.js (kind of a “framework for a framework”) and it adds two major things to Vue.js:
- Server-side-rendering of your Vue app out of the box
- Easy Vue app configuration via folders and files
Here’s one extra tidbit that Nuxt.js mentions. Developers don’t need to take advantage of either server rendering or statically generated content to find a reason to use Nuxt.js. As with the frameworks mentioned above, Nuxt.js adds some niceties on top of Vue (think automatic route configurations) that might be worth considering regardless.
Hugo
It is the world’s fastest framework for building websites. It is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again.
Features of Hugo:-
- built with Go programming language
- extremely fast
- Go is gaining traction as a language
- Site development can start quickly with built-in templates.
- useful shortcuts in Markdown
Jekyll
Jekyll is built with Ruby. Ruby was an incredibly popular programming language most notably with the Ruby on Rails framework. So, if you’re coming from a Ruby/Ruby on Rails background then you’ll want to check in with Jekyll. It is one of the Static Site Generators that has been around the longest.
Jekyll combines Markdown files with the very popular Liquid templating engine. Jekyll power the famous Github pages. This means that you can easily deploy your Jekyll site to GitHub for free!