Setting Up Static Generation0:00
There's no arguing it, static sites are absolutely the fastest, and Statamic has a static site generator. There's a lot of reasons why you might want a fully static site. If you don't have any dynamic features or forms or anything like that, or security is super important to you and you don't want anything server side, any interaction, any database, anything like that, static is a perfect candidate for you. So let's generate a static version of the site we've been building. First, let's require the package. Next, let's publish the config file. Then we'll open our project in our code editor. We'll go to config/statamic/ssg.php. And let's go through our settings. This first one shows where the static files will be saved. We're just going to leave that alone, but if you need to move that somewhere else because of a particular tool that you're using,
Running the SSG Build2:36
you can tell a failure to be thrown on errors or warnings. This is up to you. By default, this is set to false, so it will still throw a successful static site generation message when the process is over, as you'll see in a minute, even if there are technical failures. Next, let's generate our site. To do that, we run php please ssg generate. You'll see here this message about installing SpotHeatFork. We'll do that in a minute and it will increase the speed that you can generate your site in. All right, great, so we've gathered the content. We've generated 25 files. We've also copied the CSS, the JS, the CSS, and the image. We do have a couple of 404s, and these are what we were talking about a moment ago.
Fixing 404s and Previewing3:59
and we can exclude tags with a wildcard. If we rerun our generator, you can see that we have no more 404s. Next, if we open storage/app/static, you can see the whole site is here. In fact, we can symlink it. And if we go to Heavy88, now we are browsing the static site. And look at that fly. Let me show you how to use SpottyFork and multiple workers to make this even faster. composer require spotty/fork. And we have to go up a directory.
Speeding Up with Workers4:49
composer require spotty/fork. And we have to go up a directory. There we go. Require spotty/fork. And then when you run php ssg generate, please pass it how many workers you'd like to use. It's a little bit of a balancing game. I like to use 8 because I've never ran into any issues with pages being skipped or parallel processes not being finished. I've seen some people use 64. You could use 4. But basically try it out and see how fast it works for you.
