intertwingly

It’s just data

Preventing Duplicate Comments


I’ve had a persistent problem with duplicate posts from people who use Gecko based browsers.  The problem grew worse when I finally relented and had the comment form redirect to the comment you just posted instead of to the front page.

The problem is that Gecko based browsers don’t always invalidate its cache on POST requests.  People would submit a comment, have visual confirmation that the comment wasn’t there, press the back button, and then click submit again.

I previously had implemented a high tech mitigation strategy involving asynchronous XMLHttpRequests, but that too ran into its share of browser issues.

So today I implemented a pair of low-tech solutions.  The first is that I now append a single ? at the end of the URI specified in the location header and before the fragment identifier.  From the browsers perspective, this identifies a different resource.  From the server’s perspective it resolves to the same page.  This should avoid any client caching issues, people will see what they just posted, and I doubt many will even notice the subtle change in the URI.  Things will simply appear to “just work”.

Additionally, I now disable the submit button on the way out... making it a bit more difficult to simply click back then submit.  The submit button should be re-enabled in thirty seconds or so, and the hope is that that gives the high tech workaround one opportunity to kick in.