Integral Review

Welcome to my personal blog! I use it to share what I'm currently learning or thinking about, usually on topics related to technology, business, and health.

A minimalist free commenting system built with Cloudflare Workers

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>
lang-javascript

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! [Update: This blog now runs with Ruby on Rails and not with the system described. Note that Cloudflare released new services that can vastly improve this setup]

#cloudflare #development #project

💬 Comments
Subscribe to future posts