SSG is dead. Long live cache.
I don't think static site generators serve much of a purpose anymore, given that hosting is extremely turnkey and Cloudflare exists. Use your favorite web application framework for full power and Cloudflare for the speed of static.
Everything I said
Static site generators are over. I don't think you need them anymore. This is my personal website, nothing fancy, but I'm getting sub fifty, thirty, forty millisecond response times. And this is just a standard Laravel site running on Laravel Vapor. It doesn't have to be Laravel. I'm gonna show you how I have this set up, and you can use it with any framework that you want. It used to be that having a static site running on GitHub Pages was the only way that you could get something like eighteen, nineteen, twenty millisecond response times, but that's just not the case
anymore. One of the great things about static sites was you didn't have to worry about the underlying server infrastructure, maintaining it, keeping it up to date, that sort of thing. I think that's still the case. I run this site on a, a serverless solution called Vapor. There are lots of serverless solutions where this will work, and I also ship a SQLite database, which is something that I've never done before.
So I don't have any infrastructure out there. Everything is in a SQLite database. So I'm gonna walk you all the way through how I do it and how you can get this kind of response time for basically free using the web framework that you already know and love. Let me show you how. If we open the project structure here, I think the first thing to note is this is the database that I'm shipping.
It's a SQLite database, and if we take a look inside, we'll see here's all the content. This is all of the content that's on my website. There are basically no other tables. There's a migrations table that is maintained by Laravel, and then there's a SQLite table. So the only table in this database is the content table. And I know you're thinking, Aaron, shouldn't we be using MySQL?
Yes, you should be using MySQL. Go to PlanetScale.com and sign up and use MySQL. This is not sponsored. I just happen to work there. However, I am using this database in a way that I have never used a database before, and that is I only write to it in my local environment or in CI, and then I ship it off to production only to be read from.
I don't write anything to this database in production. In fact, I blow it away every time I ship to production. And so that's something, that's something that I've never done before, but it's serving me very well here. So I have all of my content here. You can see I've got different types, podcasts where I'm a host, videos I've created. If you keep going, you'll see podcasts where I'm a guest, talks, articles.
So I put all of the content that I want on my site into this database and then ship it off to Vapor. How does it get into this database is a great question. This is where having the full power of your web framework is really, really nice 'cause you just do whatever you would normally do. In my case, I wrote a bunch of commands to pull down all of these different data sources, write it to the SQLite database, and then we ship that off to production.
So to pull down the YouTube talks, all I do is I look at the YouTube API. And so here we're looking at three different channels, the personal channel, the Planet Scale channel, and the behind-the-scenes channel. We collect all of those, merge them together, and then we go through a little bit of filtering to make sure that we're only getting good videos. Um, for example, for the Planet Scale videos, I want to make sure that I'm the one that made the video, so I just use this confirm.
Do you want to add this video to your collection? If I didn't make the video, I don't want it showing up on my website. That's not very nice. And then at the bottom, we just write it into a regular eloquent model that happens to write into that SQLite database that we commit and ship off to production. There are some that are not external sources, and so something like, let's say, courses.
Courses are not external, and so what I do is I just, I just write it as an array, and then at the bottom, I just, I just write it into the database. It's that-- I mean, it's very, very simple, but anytime I add a new course, I can just come in here and drop a new item into this array, and it'll show up on my website. Um, I have enums for all the different types of, all the different types of content, and that helps me show on different parts of my site where this content should show up.
And then I have a sync all command. I have a sync all that does all of these things. And so this is the single command that I run in GitHub actions. Before I show you that GitHub action, we need to talk about the articles that I actually host on my website, not the ones that I link out. I like writing in Markdown. I find it really easy to use, and it gives me a result that I think is really pretty.
And so again, this is where having your full web application framework is really nice. I just install a Markdown package for Laravel, and anytime I want to add a new post, I just come into Views, Articles, pick the year, and drop a new Markdown file in. And the way that I have my sync command set up is it goes through this directory looking for new posts and putting them into that SQLite database.
And so when I drop a new file in here, it just shows up on my site routed and in the little picker and everything, and I can write in Markdown. So I have the same exact authoring experience that I like, but with more power because I can hook into this rendering pipeline, which I have to do Torchlight syntax highlighting and in-house ads. So in my articles, I can drop ads to the newest thing that I'm working on, and I have control over all of that.
This is all well and good, but one of my biggest problems is forgetting to update my site, right? And so I've-- I'm doing all of this stuff. I'm publishing YouTube videos. I'm on podcasts, and I just forget to put it on my website, and that seems a little bit silly. So I wanna run this on a schedule, and that's where GitHub actions comes in. I can run these commands every night at midnight and push out a new site, and that way all of my YouTube videos on my site, all of the podcasts, all of the view counts on my YouTube videos, those stay updated with zero
work on my part, which is the amount of work that I usually want to do, zero. Here's the GitHub action. You can see I do have it running on a schedule at midnight, but you know, it's midnight UTC, which is like, I think six o'clock Texas time. I don't really care. It runs once a day. That's all that matters. And anytime I push to the main branch, this is gonna run. We have a little bit of setup up here, but then the important thing is this artisan sync all.
This is that command that runs those sub commands and is gonna grab all of that content and write it to the SQLite database. This is where that database comes back. We write it to the SQLite database, and then we use this, uh, we use this action here or this job step here from Stefan Zweifel that auto-commits that. So in GitHub CI, it pulled everything down, wrote it to the database, then we commit it, and then we deploy using Laravel Vapor.
And you could deploy using whatever you want, but that's gonna ship off the newly updated database to wherever you're hosting your site. We've got our site deployed. The content is syncing down. It's deploying every night at midnight, six o'clock. It, it's doing it automatically. But we're nowhere near fast enough to say this is better than a static site generator, right?
We're still at the mercy of our application framework and our host to be really fast. And even though Laravel is the fastest application framework in the world, don't fact-check me on that. Even though it's super fast, it's not as fast as a static site generator. Well, we're not done yet. We still need to add Cloudflare on top of this.
This is the Cloudflare dashboard for aaronfrancis.com, and I am not paying for this at all. This is the totally free plan. I'm not paying for this. Um, but if you scroll down to Caching and you come to Cache Rules, you'll see I have one called Cache Everything. You can guess what this is gonna do. So if we click into Cache Everything, you'll see when the hostname equals aaronfrancis.com, which is the entire site.
That's the point. When the hostname, everything is eligible for cache and ignore, ignore whatever the server tells you and just cache it all for a day. This is the brute force, uh, cache everything all the time, everywhere rule. You could be a little more delicate with your caching rules. I just don't need it.
If, if I'm replacing a static site, I want everything to be cached. That's kinda the point. I can still make post requests to the back end and run whatever dynamics things I need to do, but for all of the pages that are coming down, they're all completely static. And so this is going to force them to be cached, and that's how we hit those 19, 20, 30-millisecond response times.
The question, the question then becomes, this is very aggressive. This is a very aggressive caching strategy. What happens when we deploy a new SQLite database with new content? I have an answer for that. We just blow the cache away. We just completely purge the cache. If cache invalidation is hard, this is the easy way out, and I'm totally fine with that.
So purge Cloudflare, the command, makes a request to Cloudflare's API for this zone, which, surprise, is not the real zone ID. That's not the real token. But it makes a request to the API and just says, "Purge everything." So whenever I'm shipping a new SQLite database that contains the new content, I call this purge Cloudflare command, and the cache is gone.
I don't have to worry about fiddling with invalidation of pages that have changed. I just blow it away, and this is totally fine. We run this on deploy. So if we look in the vapor.yaml file, you'll see here that we build the site doing all the normal stuff, and then right as the site is being deployed, we just call Cloudflare purge, and that means the new site goes live at the same time as the old cache goes away.
Problem solved. There are a lot of good turnkey hosting platforms these days. If you're like me and you don't wanna worry about the underlying server, you might check out a serverless solution like Laravel Vapor or Bref if you're using PHP. It costs me, like, five to 10 cents a month to run my site. I just don't get that much traffic, y'all. Please go visit my site. Um, I think Heroku still exists.
I haven't looked, but I think Heroku still exists. You could also get away with a $5 DigitalOcean box and just blow it away. Because one of the nice things is we're not maintaining any infrastructure. We don't have a database. We don't have a cache. You just need the language, and then everything else is SQLite and Cloudflare that does all of the heavy lifting. So try this out.
Let me know what you think. Retain the power of your web application framework, but get the response times of a static site generator. See ya.