It is still possible to build interactive features on the web without overengineering them. At least, that’s what I wanted to prove to myself when adding a commenting system to this blog.

As this website is static, I used Cloudflare Workers and their KV storage for the comments. The result is minimal: You can’t reply to a specific comment, formatting isn’t available, editing isn’t possible either.

In exchange for those tradeoffs, the worker is a single small JS file. And on the blog itself, it requires inlining a couple of lines of JS:

<script defer>
  fetch('https://example.org/comments/page-url')
    .then(response => {
        if (response.ok) {
          return response.text()
        } else {
          throw new Error('Something went wrong')
        }
      }).then(body => {
      document.getElementById('comments-list').innerHTML = body
    })
</script>

Thanks to Cloudflare’s free Workers tier, the entire system should run for free for the majority of blogs.

The code is available on Github: https://github.com/antoinefink/simple-static-comments.

If you have some thoughts about it… leave a comment!