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-javascriptThanks to Cloudflare’s free Workers tier, the entire system should run for free for the majority of blogs.
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]
💬 Comments