Home

Awesome

Staticgen

A static website generator that lets you use HTTP servers and frameworks you already know. Just tell Staticgen how to start your server, then watch it crawl your site and generate a static version with all of the pages and assets required.

About

If you're unfamiliar, you can actually use the decades-old wget command to output a static website from a dynamic one, this project is purpose-built for the same idea, letting your team to use whatever HTTP servers and frameworks you're already familiar with, in any language.

I haven't done any scientific benchmarks or comparisons yet, but here are some results on my 2014 8-core MBP:

Installation

Via gobinaries.com:

$ curl -sf https://gobinaries.com/tj/staticgen/cmd/staticgen | sh

Configuration

Configuration is stored within a ./static.json file in your project's root directory. The following options are available:

Guide

First create the ./static.json configuration file, for example here's the config for Go server, the only required property is command:

{
  "command": "go run main.go",
  "concurrency": 50,
  "dir": "dist"
}

Below is an example of a Node.js server, note that NODE_ENV is assigned to production so that optimizations such as Express template caches are used to improve serving performance.

{
  "command": "NODE_ENV=production node server.js"
}

Run the staticgen command to start the pre-rendering process:

$ staticgen

Staticgen executes the command you provided, waits for the server to become available on the url configured. The pages and assets are copied to the dir configured and then your server is shut down.

By default the timeout for the generation process is 15 minutes, depending on your situation you may want to increase or decrease this with the -t, --timeout flag, here are some examples:

$ staticgen -t 30s
$ staticgen -t 15m
$ staticgen -t 1h

When launching the command, Staticgen sets the STATICGEN environment variable to 1, allowing you to alter behaviour if necessary.

To view the pre-rendered site run the following command to start a static file server and open the browser:

$ staticgen serve

See the examples directory for full examples.

Notes

Staticgen does not pre-render using a headless browser, this makes it faster, however it means that you cannot rely on client-side JavaScript manipulating the page.


GoDoc

Sponsors

This project is sponsored by CTO.ai, making it easy for development teams to create and share workflow automations without leaving the command line.

And my GitHub sponsors:

<img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/0" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/1" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/2" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/3" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/4" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/5" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/6" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/7" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/8" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/9" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/10" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/11" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/12" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/13" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/14" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/15" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/16" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/17" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/18" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/19" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/20" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/21" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/22" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/23" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/24" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/25" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/26" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/27" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/28" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/29" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/30" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/31" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/32" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/33" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/34" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/35" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/36" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/37" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/38" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/39" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/40" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/41" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/42" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/43" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/44" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/45" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/46" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/47" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/48" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/49" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/50" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/51" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/52" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/53" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/54" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/55" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/56" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/57" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/58" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/59" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/60" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/61" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/62" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/63" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/64" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/65" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/66" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/67" width="35"> <img src="https://sponsors-api-u2fftug6kq-uc.a.run.app/sponsor/avatar/68" width="35">