Skip to content
Comic-book drawing of a mailroom clerk stamping APPROVED on letters while a trash can overflows with junk mail
My moderation queue, artist's rendering *

How in the Hell Does My Static Site Have Comments?

Phillip Harrington Nov 2026

Comments

TL;DR: Every post gets its own JSON file, and they all live in a separate S3 bucket. A Lambda takes new comments, emails me a signed approve link, and on approval appends to that JSON file. The pages stay plain HTML, nothing sets a cookie, and Lighthouse still says 100 across the board. It only took three tries to get there.

"Where's the Community?"

I was running this site past the imaginary mastermind group in my head, and Philip Greenspun showed up. If you built web things in the late '90s, you know the name: photo.net, ArsDigita, and the gospel that a website without its readers' voices is a brochure. His first question would be "where's the community?" and the honest answer was "there isn't one, it's static HTML on S3."

The usual fix is a comment widget: Disqus, giscus, pick your poison. Every one of them is somebody else's JavaScript, and most of them drop cookies. My footer says this website "doesn't set any damn cookies." I'd like to keep that promise more than I'd like comments.

So the rules were:

  • No database and no server I have to babysit
  • No cookies, no accounts, no email address from commenters
  • Every comment approved by me before anyone sees it
  • The pages stay static, and stay fast

One File Per Post

Each post's comments are a single file: /api/comments/everybody-knows-alice.json. It's a JSON array of name, comment and date. That's the whole database.

My first instinct was to bake comments into the page HTML. That fights the deploy: the deploy uploads pages without comments, so every deploy would have to re-bake every page that has them. Keeping the comments in their own file makes the two completely separate. Deploys change pages. Comments change JSON. Neither touches the other.

They also live in their own S3 bucket, because my deploy script deletes anything in the site bucket that isn't in the build. That's the right behavior for a site and the wrong behavior for other people's words.

CloudFront does the routing, all on my own domain:

  • GET /api/comments/<post>.json goes straight to the comments bucket, cached. Reading comments costs zero compute.
  • POST /api/comments goes to a Lambda
  • /api/moderate goes to the same Lambda

CloudFront matches routes by path, not method, but /api/comments and /api/comments/* are different patterns, so the reads and the writes can share a prefix.

Posting a Comment

The form at the bottom of every post is a plain HTML form. Name, comment, submit. It works with JavaScript turned off. The Lambda:

  • Checks a hidden "website" field that people never see and bots always fill in. If it's filled in, the bot gets a cheerful "thanks, awaiting approval" and nothing happens.
  • Validates the name and comment lengths and strips control characters
  • Checks the post is real and actually has comments turned on
  • Emails me
  • Redirects back to the post with a status code in the URL

That status code is ?comment=pending, or missing, too-long, invalid, error. The page's script maps those five codes to its own messages and ignores anything else. So nobody can send someone a link like ?comment=You+have+been+hacked and put words on my page.

If the post fails, the script also saved the draft before submitting, so nobody loses the life of John to a typo in their name.

Moderation Without a Queue

Here's the part I like best. There's no "pending comments" table, because there's no table at all. The comment rides inside the approve link in the email, signed with a secret key (an HMAC) so nobody can forge one or edit the text, and it expires in two weeks.

To approve a comment, I click the link. To reject one, I do nothing. Spam doesn't pile up anywhere except my inbox, and it goes stale on its own.

$2 tip: never let a GET request approve anything. Email security scanners open every link in every message to check it for malware. If clicking the link approved the comment, the scanner would approve everything before I ever saw it. So the link opens a confirmation page, and the Approve button on that page is a POST.

On approve, the Lambda appends the comment to the post's file, skips it if that comment is already there (double-clicks happen), and clears that one file from the CDN cache.

Showing Comments

A few lines of JavaScript fetch the post's JSON and fill in a template with textContent. Never innerHTML. Commenter text is only ever text, so if someone's name is <script>alert(1)</script>, that's exactly what you'll see, and nothing runs.

The comment markup lives in a component in my site's repo, not in the data. Restyling the comments is a normal deploy.

Lighthouse Strikes Back

Everything worked. Then I ran Lighthouse on /everybody-knows-alice#comments and Performance dropped to 80.

The culprit was layout shift: 0.471, where anything over 0.1 is bad. Open the page at #comments and the browser jumps straight to the comments section. A moment later the comments arrive, appear above the form, and shove it down the screen. That's also exactly where everybody lands after posting a comment, so it wasn't just a Lighthouse thing.

Try one: take #comments out of the URL before the browser jumps. Didn't work. Chrome decides where it's jumping at the very start of the navigation.

Try two: take away the jump target instead. A tiny inline script removes the heading's id before the first layout, so there's nothing to jump to, then puts it back and scrolls there once the comments are in. Still a layout shift. A timeline trace showed why: my scroll ran in the same animation frame as the comments being drawn, and Chrome scores shifts per frame.

Try three: draw the comments while still at the top of the page, where they're off-screen and moving them doesn't count, then wait a frame and scroll. Layout shift: 0.

Then Performance was 99, because the comments request waited for my JavaScript file to download and run first. The same inline script now starts the comments request the moment the browser reads that part of the page, so the two load side by side instead of one after the other. 100.

One more: a post with no comments yet asked for a file that didn't exist, and the 404 landed in the browser console, which costs a Best Practices point. Now the deploy creates an empty [] file for every post that has comments turned on, using S3's create-only-if-missing upload so it can never overwrite real comments. 100s straight across.

Steal This

This whole site is open source, comments included:

It's almost build-system agnostic, too. The Lambda, the CloudFront routes and the script are plain AWS and plain JavaScript. The two components are a copy-paste into whatever templates your site uses. The catches: posts have to live one level deep ( /some-post, not /blog/2026/some-post), and the deploy step that makes the empty files expects flat page files.

The secrets live in AWS, not in the repo. Nice try.

What It Costs

Pennies a month. One S3 bucket, one small Lambda, a few CloudFront routes, and the email service I already had set up. The pages still load fast as fuck-all get-out.

And in the spirit of full disclosure: I've spent more words planning this setup than people will ever spend using this setup. Prove me wrong. The form's right down there.

Comments

    Add your comment

    Comments show up after I approve them. No email address needed. Still no cookies.