When you view a post's edits, it shows a very granular level of change monitoring (down to the character). My question is, is this done client-side as part of the WMD editor JavaScript code, or is it done using a server-side text comparison? I would like to do something similar, and I can see the advantages and disadvantages to either approach. The one on Stack Overflow seems to work very well, though.

I saw a couple of close votes, so let me rephrase this to be more "on topic".

I want to replicate the functionality that is demonstrated by Stack Overflow's granular recording of post edits. What are the pros and cons of implementing this type of functionality client-side with the WMD editor's JavaScript code or server-side with a text comparison?

  • Are you talking about the actual look that SO uses (with strikes, etc), or how it is done programmically (just finding the changes)?
    – Jess
    Commented May 8, 2011 at 0:09
  • it's all in the javascript
    – Ibrahim Diallo
    Commented May 8, 2011 at 0:10
  • The actual what? If you see a post that has been edited, then you can view the edits. It shows where text was added, where text was removed, etc. Commented May 8, 2011 at 0:10
  • just finding the changes Commented May 8, 2011 at 0:14
  • Are events raised for each keydown to save the key strokes? Or is a comparison of the text done after the fact? Commented May 8, 2011 at 0:15
  • I'd guess that the changes in the edit are the result of a diff done on the content rather than keeping track of what the user actually entered when editing the post. That said, I have basically no authority on the matter. Commented May 8, 2011 at 0:18
  • 3
    It's basically a simple text diff. Not sure what exactly SO is using, but it's quite a commonly used utility. en.wikipedia.org/wiki/Diff
    – deceze
    Commented May 8, 2011 at 0:19

2 Answers 2


The PostHistory table on SEDE reveals this if you dig in far enough.

Posts are broken down into 3 components: title, body, and tags. This is done to improve concurrency (there are only collisions when multiple users edit the same component) and to promote storage conservation (if a question is retagged, there's no need to store a new copy of the body).

For each revision, the changed components are each stored in a PostHistory row that contains the entire contents of the field. For completeness: the Posts table row always contains the current state of the post -- the only difference is that the body is in a 'cooked' state (i.e., HTML ready for page output), whereas the PostHistory row contains the original Markdown.

When an edit history is displayed, each field's contents from the previous applicable revision are diff'd server-side. Treatment of the tags field may be different than for title and body, as it's a much simpler field to process. I'm not sure of the method by which they do the text diffs; it's probably an open-source-based implementation of some kind.


I'm not sure exactly how it's done on here, but the accepted answer on this question offers a C# solution: How to find difference between two strings?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .