Every time I need to compare two JSON payloads or two config files, I end up pasting internal data into some random diff website. That is a bad trade: convenience in exchange for shipping logs and API responses to a third party.

So I built Difflin: a diff tool with no backend at all. The comparison happens inside the browser tab.

What it actually does

The engine is a classic LCS (longest common subsequence) dynamic-programming diff — the same idea behind diff and early git diff implementations — with a line-level pass first and an optional character-level pass inside changed lines.

// core idea, simplified function lcs(a, b) { const dp = Array.from({ length: a.length + 1 }, () => new Uint16Array(b.length + 1)); for (let i = a.length - 1; i >= 0; i--) { for (let j = b.length - 1; j >= 0; j--) { dp[i][j] = a[i] === b[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]); } } // walk the table backwards, emitting 'equal' / 'delete' / 'insert' ops } 

Notes from building it:

  1. Use typed arrays for the DP table. A plain array-of-arrays with 1,000 × 1,000 entries is 1M boxed values; a Uint16Array per row is friendly to the allocator and keeps GC pauses out of typing latency.
  2. Diff lines first, characters second. Running character-level LCS on the whole document is O(n·m) in characters, which explodes. Doing it per changed line keeps it interactive while still highlighting exactly which words moved.
  3. JSON mode normalises before comparing. Parsing both sides and re-serialising with sorted keys means {"a":1,"b":2} and {"b":2,"a":1} compare as equal — which is what you want when debugging API responses, and is not what a raw text diff tells you.
  4. No build step. A single ES module plus the DOM. node --test covers the diff engine (7/7 tests passing), and the same file is imported by both the browser page and the tests.

Why browser-only matters

Beyond privacy, there is a boring operational benefit: there is nothing to run. No Docker image, no cold start, no rate limit, no expiry of your pasted text in someone's S3 bucket. Open the page, paste, done — and it still works offline once loaded.

If you find it useful

The tool is free and MIT-licensed. If it saves you time at work and you want the hosted version to keep existing (custom domain, JSON-schema-aware comparison, saved sessions), you can leave a tip:

Bug reports and PRs are more valuable than tips — especially test cases where the character-level pass produces a confusing highlight.

Repo: https://github.com/qtnt2xxx-wq/difflin-lcs-diff