Static HTML Comments
sive.rs
sive.rs
If you've got Ruby listening for updates with a postgres database all tied into a content generator it's probably time to admit you don't have a static website anymore and just look for best practice ways to go about this (with a bit more security!).
We might also be blurring lines of static sites vs interactive sites. You can have a static site that does nothing but allows the user to scroll to view it. You can also have static sites that change and do things based on the user's input. Entire games have been made using client-side JS but is still served statically.
https://simonhearne.com/2020/network-faster-than-cache/ has some discussion.
It doesn't. Browsers will happily render half an HTML page as it's streamed in. There's an interesting HTTP 203 on this. https://web.dev/shows/http-203/LLRig4s1_yA/ if you're interested.
Worried that Postgres will tip over? Just read from the DB, but cache the results in memory with a short TTL on your Ruby server.
Or, if you’re worried about not just Postgres, but also your Ruby server getting overloaded, just go with a fully server rendered page, and cache the whole page. Could use NGNIX cache, as you’re already using NGINX, or a CDN, or Varnish, whatever. No JS loaded comments at all.
Either way, caching should be able to get you tonnes of scalability, easily avoid hug of death, without resorting to PG triggers calling a Ruby server that writes files to disk.
With that being said, this approach works too, and if it’s just a personal page with you as the only dev, you understand it, so it’s all good. But I’d certainly avoid this approach at a company, largely because it’s unusual and will take new devs longer to wrap their heads around.
It's fun to make architecture like in the article though, I'm guilty of it as well with previous hobby projects
Also, with my suggestions, you can cache invalidate too, if a short TTL isn’t good enough. Based on writing files to local disk, it seems like a “single server” scenario, so invalidating the in-memory cache on POST comments is dead simple, and can be truly immediately consistent. Likewise, for full page caching, if using Varnish as a cache, Varnish lets you invalidate easily too. NGINX and CDNs don’t (generally), but if a short TTL isn’t enough, and you need instant invalidation on new comments, then just go in-memory cache or Varnish.
I believe this was the technique used (and still being used?) by 2chan, the ancestor of the infamous 4chan. It didn't even need a database, as it was entirely file-based and simply appended each post to the appropriate file. Visitors were served static HTML with no JS required.
This way all you need is a POST endpoint (which might just be a cgi script) to receive the comment and update the comment file.
Gets more complicated if you support threaded comments or pagination, but for a linear comment system it should be more than enough.
To comment a visitor takes any url on the domain and appends "/@say/". Like http://notmyurl.com/somepage.html/@say/Some response to somepage. Or "...lakephoto.jpg/@say/Cool fish! How long was it?"
The perl script sees the /@say/ in the logs and adds the parsed out and sanitized comment to an .html file. There's some nginx location hijinks for matching /@say/ URLs that goes to a confirmation page and redirects to the comment listing page.
I clicked on your link expecting a real site (my monkey mind having skipped over the actual URL contents) and I was redirected to some other odd Chinese (?) URL with spammy ads and NSFW content.
At that time in the 90s this was heavily deployed everywhere. This was before PHP-BB and other database based boards got popular.
I guess it's a completely foreign concept in the age of SPAs when everything is dynamically generated in the browser.
Anyone who copy/pastes that example is going to have a rough time.
I wrote a forum that regenerated the static files when a post is added. Including the user's own account pages, those were statically generated too.
In theory a change to a user's account should only change that user's account pages.
I wrote a medium article about it. I was trying to get as many requests per second while logged in. It's an extension of the cache invalidation problem.
I got to 3288 requests per second on a virtual machine. A static site should get at least 12,000 requests per second. For reference, Visa and Mastercard process 40,000 requests in total per second for financial transactions. I use an nginx authenticator and Rust authentication program that talks to Redis to check the IP address of a user's session token in the URL. You could probbaly improve the performance further by using an embedded Lua script in Nginx and using that to authenticate IP address rather than doing a HTTP request for each request that the nginx authenticator does.
You can see the static site as a cache that needs to be updated based on new inputs.
https://medium.com/@samuelmichaelsquire/1633-requests-a-seco...
It would be so nice to have a comment system like Disqus but simple like described here, that also had an easy tie-in to a spam prevention service (or would work with a trained spam prevention model).
A separate authentication layer is entirely possible, at the loss of anonymity.
https://nextjs.org/docs/basic-features/data-fetching/increme...
A better approach IMO. Why require js for something as trivial as adding a small block static html to a page every time it loads? Makes no sense.
Here is an incomplete try: https://github.com/hadrianw/compend
Lock and unlock is there for moments when someone wants to modify the content or moderate comments while still allowing commenting.
I'm using Cloudflare to do this, and any kind of db updates will update the cache. I'm new to all this, but wouldn't this be spiritually the same, e.g. if the cache would serve the latest db content instead of hammering the db? (I'm doing this because I'm using Airtable as db, and it's incredibly slow, rather than a "hug of death" kind of scenario)
That was the initial implementation for supabase’s real-time updates (afaik) and for this reason they had to resort to read the WAL.
If your application is down when the NOTIFY is triggered that comment is lost, isn’t it?
document.getElementById('commentlist').innerHTML = xhr.responseTextIt's the right setup for write rarely, read often scenarios.