Why Static Sites Are Awesome
I recently put together a tool to find cheap mini PCs. It started as a Python script that pulled data from eBay, did a bunch of parsing, and printed the results to the terminal. I figured, "Hey, maybe someone else would find this useful." So why not turn it into a website?
My first thought: Let’s use Flask! Python in the back, maybe some SvelteJS for a reactive front-end... and before I knew it, I was getting overwhelmed. Then I remembered a site I’d seen a while ago, diskprices.com (which I later took a lot of inspiration from), that compared Amazon listings for storage. I peeked at the source code, and to my surprise, it was just a single HTML page with no backend. I thought, "Wait... can I do that too?"
I closed all my tabs about the “best web frameworks for 2024,” shut down my computer, and stepped away. I came back to it the next day, determined to keep things simple. Just get it done.
First, I asked Claude (my AI assistant) for advice:
"...There are a few approaches we could take, but one straightforward method would be to create a simple web application using Flask, a lightweight Python web framework."
Oh no.
"Is there anything simpler?" I asked.
"...We can create a basic HTML page that uses JavaScript to fetch and display the data from your API."
That would mean API requests on each page load.
"Is there an even simpler way?" I repeated.
"How about a static HTML page that displays pre-fetched data?"
That was it. I realized I didn’t need anything fancy. I could just run my Python script periodically, save the data to a JSON file, and load it into a static HTML page. Vanilla JavaScript could handle sorting and filtering. I did have to use a static site generator, Eleventy, to load the JSON onto the page, but it wasn't hard to set up. Using its templating engine (similar to Jinja2), I could loop over the data and generate a single HTML page. Now whenever I ran my script, the page rebuilt to show new data.
What about hosting? How much would it cost? After a bit of research, I learned you can use Cloudflare Pages for free hosting of static sites, hopefully with no surprise bills. I connected a GitHub repo, pushed my code, and had Cloudflare rebuilding the site every time the repo updated.
But what about running the script? Surely I need to pay now, right? Turns out you can use GitHub Actions to do this for free. So I (well, Claude) wrote a workflow to run the script on a cron schedule and commit the new JSON to the repo. After testing it once, I went on to other things, trying to forget about it.
The next morning, I checked to find everything working. The data had updated every hour, and it just... worked.
I submitted it to Hacker News and it hit the front page. Honestly, I was nervous. Could Cloudflare handle the traffic? Would it get hugged to death? It got 275k requests that day, and no, nothing happened. It just kept working. All for free.
That’s the beauty of static sites. They’re simple, fast, and get the job done without all the headaches. Sometimes, simpler is better.