See exactly what changed.
Compare text, code, documents, data and images. Free, no ads, and comparing never uploads your text. Saving to an account is optional and end-to-end encrypted.
Open text.compare · Choose a version · Host your own · How it works · Support the project
| text.compare full you are here |
text.compare lite |
|---|---|
|
Everything behind text.compare. The diff tool plus optional extras, each off until you configure it.
Best for: running your own public site with accounts. |
The simplest way to self-host. Static files only, no backend code, nothing to configure.
Best for: your laptop, a company network, or free static hosting. |
Comparing two pieces of text is a simple job, but most free diff sites wrap it in banner ads, cookie walls and upsells, and many quietly upload whatever you paste to their servers. That's a bad deal when the text is a contract, a config file with secrets, or your own writing.
text.compare is the diff tool I wanted instead: fast, clean, private by design, and good at the hard cases like moved code, reformatted JSON, PDFs and Word documents. It's open source, so you can check every claim below, or run your own copy in a couple of minutes.
- Side by side or unified, with changed words or single characters highlighted inside each line
- Moved blocks are shown in violet with a tag like Moved to line 12 that jumps to the other copy, instead of appearing as a big deletion plus a big addition
- Syntax highlighting for 100+ languages, picked from the file name or the text itself
- Change map beside the editor, F7 / Shift+F7 to step through changes, and an option to hide unchanged lines
- Merge as you go: both sides are editable, with undo, find and replace, and arrows that copy a block across
- Ignore upper/lower case, spaces at line ends, all whitespace or blank lines
- Ignore anything matching a pattern: ready-made ones for dates and times, GUIDs, hex values and numbers, or your own regular expressions (made for comparing log files)
- Library with your saved comparisons and a history of recent ones, searchable, one click to reopen
- Works without an account: everything is kept in your browser
- Optional accounts (Google or an email link) keep your library on every device, end-to-end encrypted with a passphrase only you know, plus a one-time recovery code
- Export all your data, delete it all, or delete your account yourself, any time
- Copy link puts the whole comparison inside the link itself, along with the view settings (split or unified, document mode, word or character highlights). Nothing is stored anywhere
- Report: a self-contained HTML redline to send to someone, or print it straight to PDF. Side by side or unified, the whole text or only the changes, your choice, and document mode carries over as wrapped serif paragraphs
.patchdownload in standard unified format (works withgit apply), or copy the diff- Tools to format JSON with sorted keys, sort lines, strip trailing spaces and swap sides
- Light and dark themes, a phone layout, and offline support once installed as an app
| Where it goes | |
|---|---|
| Text you paste or type | Compared in your browser tab. It only leaves the browser if you sign in, and then only as encrypted history and saves (see below) |
| Files you open (PDF, Word, Excel, images) | Read in your browser; the files themselves are never uploaded. If you are signed in, the text taken from them is saved like any other text, encrypted first |
| Copied share links | The text rides in the part after #, which browsers never send to a server |
| History and saves when signed out | Kept in this browser only (IndexedDB). History can be turned off in Options |
| History and saves when signed in | Uploaded to your account in Supabase, end-to-end encrypted in your browser first. The database holds only ciphertext, plus which account owns each item, whether it is history or saved, its size and timestamps |
| Your passphrase and recovery code | Never sent anywhere. Supabase only stores your data key locked with them, so neither Supabase nor the site owner can decrypt your saves |
| Your account | Supabase keeps your email address and sign-in details. The site owner can see your email, how many items you have and how much space they use, never what is in them |
| Contact preference | Off unless you turn it on in account settings; stored with your account so the site owner knows whether you are happy to hear about other apps |
| Analytics (on at text.compare, off unless configured) | Google Analytics sees the page address only, never the text, the # part or sign-in codes |
| Usage statistics (on at text.compare, off unless configured) | Anonymous daily counts of what kind of comparison was made (for example "a Word file, about 500 lines"), never your text or who you are |
Comparing never sends anything over the network; only your library does while you are signed in, and it is encrypted first. The included server configs set a Content Security Policy that blocks every outside script and connection except the optional analytics tag and the optional account service.
text.compare is a static site: HTML, CSS and JavaScript. All the comparing happens in the browser.
The only server pieces are optional: Supabase for accounts, and a small server in server/ for the
anonymous usage counts and admin panel.
flowchart LR
subgraph Input
T[Pasted text]
F[Files: .txt .pdf .docx .xlsx]
I[Images]
end
F -->|PDF.js, unzip + XML| T
T --> N[Normalise lines<br/>case, whitespace,<br/>ignore patterns]
N --> D["Line diff<br/>Myers O(ND)"]
D --> W[Word / character diff<br/>inside changed lines]
D --> M[Moved-block detection]
W --> E[CodeMirror merge views]
M --> E
D -.->|background worker| S[Stats and similarity]
T --> J[Data view<br/>JSON / CSV structure diff]
I --> P[Pixel diff on canvas]
The diff engine
Lines are compared with Myers' O(ND) algorithm in its linear-space form (middle-snake bisection), after trimming the common start and end. Each distinct line is mapped to an integer first, so the algorithm compares numbers, not strings. A time budget makes pathological inputs fall back to a coarser result instead of freezing the page; an 8 MB log compared against an edited copy finishes in about two seconds.
Inside each changed block a second pass diffs tokens: whole words in word mode, or code points in character mode (so emoji are never split). Those ranges become the highlighted spans.
Source: src/seq-diff.ts, src/diff-core.ts, src/worddiff.ts
What counts as a change
Every option works by normalising a copy of each line before comparing: patterns are replaced with a placeholder, then whitespace is trimmed or removed, then case is folded. Lines that match after normalising count as equal, but the editor still shows your original text. Blank lines can be skipped entirely, so extra spacing never shows as a change.
The same normalised diff drives the editor highlighting through a custom diff function handed to CodeMirror, so what you see and what's counted always agree.
Source: src/normalize.ts, src/merge-override.ts
Moved blocks
After the diff, removed runs of lines are looked up among inserted lines. A run that reappears elsewhere (two or more non-blank lines, or one line of 30+ characters) is a move. Moves are found from the editor's own change blocks, so the violet highlight always lines up with the red and green around it.
Source: src/moves.ts, src/moved-deco.ts
Data view
JSON is parsed and walked as a tree. Object keys are compared as sets, so key order never
matters. Arrays whose items all carry a unique id, key, _id, uuid, code or name are
matched by that field; other arrays are compared by position. Each difference is listed by its path,
such as items[id=3].price.
CSV/TSV is parsed with full quoting support after detecting the delimiter. Columns are matched by header name. Rows are matched by the first column when its values are unique on both sides, and otherwise by a diff of the rows in order.
Source: src/structure.ts
Files
- PDF: text is extracted page by page with PDF.js, loaded only when you open a PDF
- Word (.docx) and Excel (.xlsx) are zip files of XML: they're unzipped with fflate and read directly, one line per paragraph or one CSV row per spreadsheet row
- Text is decoded as UTF-8, UTF-16 (by byte-order mark) or Windows-1252, and binary files are refused
- Images are drawn to a canvas and compared pixel by pixel
Source: src/documents.ts, src/office.ts, src/pdf.ts, src/pixeldiff.ts
Accounts and end-to-end encryption
Accounts are optional and use Supabase for sign-in and storage. The server never sees what you save, your passphrase, or your recovery code.
flowchart TB
P[Your passphrase] -->|PBKDF2-SHA256, 600,000 rounds| K1[Passphrase key]
R[Recovery code, shown once] -->|PBKDF2-SHA256| K2[Recovery key]
D[Random 256-bit data key] -->|AES-GCM, locked by| K1
D -->|AES-GCM, locked by| K2
C[Comparison] -->|gzip, then AES-256-GCM with the data key| X[(Ciphertext in the database)]
- When you first sign in, your browser creates a random data key. It is stored only in locked form: once locked by your passphrase and once by a recovery code that is shown to you a single time.
- Every saved comparison is compressed and encrypted with AES-256-GCM before upload. Each piece of ciphertext is bound to its row, so rows can't be swapped or replayed.
- Changing your passphrase re-locks the data key; nothing else has to be re-encrypted.
- "Stay unlocked on this device" keeps a non-exportable copy of the key in the browser's IndexedDB, so it can be used on this device but can't be read out. Signing out or locking removes it.
- The database stores ciphertext plus the minimum to run the service: the owner, whether an item is history or saved, its size and timestamps. Row-level security limits every user to their own rows, and each account is capped at 100 MB and 1,000 saved comparisons, with history trimmed to the latest 200.
- If you forget your passphrase and lose your recovery code, nobody can recover your saves. That's what end-to-end encryption means.
Source: src/account/crypto.ts, src/account/library.ts, supabase/schema.sql
Share links
sequenceDiagram
participant You
participant Browser
participant Server as text.compare server
participant Friend
You->>Browser: Copy link
Browser->>Browser: JSON, then lz-string compression
Browser-->>You: text.compare/#v1:N4Ig…
You->>Friend: Send the link
Friend->>Server: GET / (the #… part is never sent)
Server-->>Friend: The static page
Friend->>Friend: Page reads #v1:…, restores both texts,<br/>then clears it from the address bar
The text is compressed with lz-string into the URL fragment. A tiny script at the top of the page removes the fragment from the address bar before any other script runs, so it can't leak into analytics or browser history tools.
Source: src/share.ts
The build is a folder of static files, so it runs anywhere that serves files: a $5 VPS, a Raspberry Pi, GitHub Pages, Cloudflare Pages or Netlify. It needs no database, no server code, and no outside services. Accounts and usage counts are optional extras (see Optional: accounts).
git clone https://github.com/JamesClayPatton/text-compare.git
cd text-compare
npm install
npm run build # the site is now in dist/You need Node.js 22.12 or newer to build (24 LTS recommended; see .nvmrc). Visitors only need a modern browser.
docker build -t text-compare .
docker run -d --restart unless-stopped -p 8080:80 --name text-compare text-compareOpen http://localhost:8080. The image serves the site with nginx, with long-lived caching for
hashed assets and the same security headers as the live site (nginx.conf).
diff.example.com {
root * /srv/text-compare/dist
encode gzip zstd
header /assets/* Cache-Control "public, max-age=31536000, immutable"
header /sw.js Cache-Control "no-cache"
file_server
}| Host | Build command | Output folder |
|---|---|---|
| GitHub Pages | Fork, then Settings → Pages → Source: GitHub Actions, and run the Deploy to GitHub Pages workflow | built for you |
| Cloudflare Pages | npm run build |
dist |
| Netlify / Vercel | npm run build |
dist |
All paths are relative, so the site also works from a sub-folder such as example.com/diff/.
Settings are read when you build. Put them in .env.local (git ignores it; see
.env.example) or pass them as environment variables.
| Variable | What it does | Default |
|---|---|---|
SITE_URL |
Your public address, used for canonical links, the sitemap and link previews | https://text.compare |
VITE_GA_ID |
A Google Analytics 4 measurement id (G-…). Leave empty for no analytics at all |
empty |
VITE_SUPABASE_URL |
Your Supabase project URL, to turn on optional accounts | empty |
VITE_SUPABASE_PUBLISHABLE_KEY |
Your Supabase publishable (anon) key. It is meant to be public; never use the secret or service-role key | empty |
VITE_USAGE |
on turns on anonymous usage statistics (needs the admin server below) |
empty |
SITE_URL=https://diff.example.com npm run buildWhen VITE_GA_ID is set, the tag reports only the page address (never the text or the # part),
turns off Google signals and ad personalisation, and keeps analytics cookies off by default for
visitors in the EEA, UK and Switzerland. Remove the Google hosts from the Content Security Policy
in your server config if you don't use analytics.
Without Supabase settings the site has no sign-in button, and the library keeps everything in the visitor's browser. The accounts guide explains why accounts use Supabase, how sign-in works, which key goes where, and how to run and troubleshoot it. The short version:
- Create a free project at supabase.com.
- Open SQL Editor, paste all of
supabase/schema.sqland run it. It creates the tables, row-level security, limits and the delete-my-data and delete-my-account functions, and is safe to run again. - Under Authentication → Sign In / Providers, keep Email on and, if you like, turn on Google
(you'll need an OAuth client from Google Cloud whose redirect URI is
https://<your-project>.supabase.co/auth/v1/callback). - Under Authentication → URL Configuration, set the Site URL to your address and add
https://your.domain/**to Redirect URLs. - Put the project URL and publishable key in
.env.localand rebuild. - Make sure your Content Security Policy allows
https://*.supabase.coinconnect-src(the includednginx.confalready does).
Supabase's built-in email service only sends a few sign-in emails an hour, so connect your own SMTP provider (for example Resend) under Authentication → Emails before going live.
server/ is a small optional Node server (Node 24 or newer, nothing to install) behind an
admin panel at /admin/, with anonymous usage statistics and, if accounts are on, your account list.
- Copy
server/.env.exampletoserver/.envand setADMIN_PASSWORD. - Run it with
npm run server(it listens on127.0.0.1:8786) under your service manager of choice. - Send
/api/*to it from your web server, for example in Caddy:handle /api/* { reverse_proxy 127.0.0.1:8786 } - Build the site with
VITE_USAGE=on.
To list accounts too, see the accounts guide.
- Page titles, descriptions and the text below the tool for the home page and each landing page (
/json-compare/,/pdf-compare/and so on) live insite/pages.ts. Add an entry and the build creates the page and adds it to the sitemap - Colours are CSS variables at the top of
src/styles.css, with light and dark sets - Icon and share image are in
public/ - Search engine key:
public/55801fe4eb037647115719a2769a5b6f.txtis text.compare's IndexNow key. Delete it in your copy and make your own if you want to notify Bing about your pages
git pull && npm install && npm run buildBuilt files have content hashes in their names, so visitors get the new version on their next visit.
npm run dev # dev server with hot reload at http://localhost:5173
npm test # unit tests (Vitest)
npm run test:e2e # browser tests (Playwright); run `npx playwright install chromium` once
npm run build # typecheck, then build to dist/Project map
src/
main.ts page wiring: toolbar, modes, files, export, sharing
editor.ts CodeMirror side-by-side and unified views
seq-diff.ts Myers diff on integer sequences
diff-core.ts line diff, stats, .patch output
worddiff.ts word and character highlighting
normalize.ts comparison options and ignore patterns
merge-override.ts feeds the options into CodeMirror's diff
moves.ts moved-block detection
structure.ts JSON and CSV structural comparison
report.ts the HTML report
documents.ts opening any file type
office.ts, pdf.ts Word, Excel and PDF text extraction
pixeldiff.ts image comparison
share.ts share-link encoding
account/ optional accounts: encryption, library storage, Supabase sign-in
analysis*.ts stats in a background worker
ui/ change map, data and image panels, popovers, toasts
site/
pages.ts landing page content and SEO metadata
analytics.ts optional Google Analytics tag
tests/ unit tests
e2e/ browser tests
The unit tests cover the diff engine, options, moves, structure diffs, reports, file readers and share links. The browser tests drive the real page: typing, merging, share links, every landing page, and opening real PDF, Word, Excel and image files.
Bug reports and pull requests are welcome. Please run npm test and npm run test:e2e before
opening a pull request, and keep the privacy promise intact: nothing a user compares may leave the
browser. By contributing you agree that your contribution is licensed under the AGPL-3.0, like the
rest of the project.
text.compare is free and will stay that way, with no ads. If it saves you some time, you can buy me a coffee. It genuinely helps keep the site running.
Copyright © 2026 James Patton (jamesclaypatton.com).
text.compare is free software under the GNU Affero General Public License v3.0. In short:
- Use it, study it, change it and host it, for personal or commercial use.
- If you run a modified version as a website, publish your source code under the same license and link to it from the site. The footer's Get the code on GitHub link does this for the original.
- Keep the credit: copies must keep the Made by James Patton attribution in the footer. You can add your own name next to it. See NOTICE for the exact terms.
Built with CodeMirror 6, PDF.js, fflate and lz-string.
![Data view listing JSON changes by path, such as items[id=2].price changed from 7 to 8](/JamesClayPatton/text-compare/raw/main/docs/data-view.png)

