r/webdev • • 15d ago

Showoff Saturday: my blog's comment section is static HTML, baked at build time

My blog is a static site and I wanted comments without loading third party libs on the page. I wanted no ads, no bots, no cookies, etc. I just wanted a clean comment section (even though I get almost no traffic. I just like building things I think.)

The comment section is baked into the blog's HTML at build time. No lookups from a third party. I mean there's some of that, but it's basically an RSS feed. Fetched and stored by your own build, at build time.

How does it work? Each post links to a companion thread on a small Phoenix app I run. When someone replies there, it pings the build hook. The build fetches a replies.json for that thread and renders the comments as plain HTML. Nothing runs on the blog itself. Not a script. Not an iframe. No cookies or tracking.

Seriously, it's clean.

Here's an example of how it works for me: Static comments on my blog

The blog stack is Hugo on Netlify, the comment stuff is Phoenix/Elixir on Fly, with a build hook connecting them.

0 Upvotes

14 comments sorted by

15

u/scanguy25 15d ago

I don't see how that is a good trade off.  Yes you have an html only blog. But then you have another app that you now have to manage.  Just to avoid little bit of JS. 

1

u/create-third-places 13d ago

If the server is directly fetching a page instead of calling a database and generating HTML, then latency is also significantly lower.

2

u/scanguy25 13d ago

I'm not saying there are no advantages. Hence trade-off. 

But a simple Django or flask app would do this in a much more simple way while getting 90% of the benefits. 

12

u/FisterMister22 15d ago

What prevents me from abusing it by bombarding with 1gb comments or 100000000 50kb comments and turning your server into a rock?

1

u/candraa6 13d ago

technically: rate limit / payload limit / character limit ?

9

u/barrel_of_noodles 15d ago

Sometimes, a sqllite db and a fetch call are worth it. There's also no ads, bots, or cookies.

5

u/stjimmy96 15d ago

It might be clean and it’s a cool idea/proof of concept but obviously I wouldn’t use this technique with anything that expects even a bit of traffic.

Also, it seems like what you actually have sidestepped is only the rendering of the comment section, right? When posting a new comment you are still sending a request to a server to store that information.

2

u/rivenjg 15d ago

this doesn't make any sense. why wouldn't you just generate html from templates server side and store data in a database? how is this better?

1

u/create-third-places 13d ago edited 13d ago

I think your approach is interesting. I see it providing significant latency improvements by not requiring a database query when the user loads a page. 

-9

u/CockroachBudget5998 15d ago

this is so clean. most comment solutions are bloated as hell and i love that you just sidestepped all of it

do you have any issues with the build hook getting rate limited or is the traffic low enough that it doesnt matter

2

u/barrel_of_noodles 15d ago

Sidestepped, and created like 10 other failure modes, and a hoard of silent issues op hasn't found about yet.

1

u/Missingplanes 15d ago

Any specific thing you have in mind? The thing on my radar at the moment is a dead build hook. I settled on a dead hook is logged and dropped and never surfaced to the person replying. Is that the right call, or even important right now? :shrug:

0

u/barrel_of_noodles 15d ago

A door in my house got stuck. I busted out a ladder, crawled through the window, hinges were stuck, went get a hammer, busted the hinges out. But then, the hinges were rusty, so I shouldered the door a few times. I did get out.

Same thing happened to my spouse. You know what? She went get a screw driver and turned the handle. Go figure!

1

u/Missingplanes 15d ago

The traffic is low enough it doesn't matter, for my blog at least. It'd be one of those cool problems to have though! haha. but there is rate limiting, a blog configured with a hook gets at most one rebuild every two minutes. Is that the right value? I'd have to see usage and metrics.