For very large files (e.g., > 100K lines), it is recommended to perform the diff calculation on a Python server to avoid browser performance issues. Because jsdifflib's API matches Python's difflib.SequenceMatcher exactly, you can compute the opcodes in Python and send them to the client.
Server-side (Python) requirement:
Your backend should use Python's difflib.SequenceMatcher to generate opcodes and return a JSON object containing:
baseTextLines: The original lines.newTextLines: The new lines.opcodes: The result of SequenceMatcher(a, b).get_opcodes().baseTextName: Title for the base text.newTextName: Title for the new text.
Client-side (JavaScript) requirement:
Once the JSON data is received, pass it directly into diffview.buildView().
// Example Python backend logic (conceptual)
@jsonify
def diff (self, baseText, newText, baseTextName="Base Text", newTextName="New Text"):
opcodes = SequenceMatcher(isjunk, baseText, newText).get_opcodes()
return dict(baseTextLines=baseText, newTextLines=newText, opcodes=opcodes,
baseTextName=baseTextName, newTextName=newTextName)
// Example Client-side consumption
// Assuming 'data' is the JSON response from the server
// data = { baseTextLines: [...], newTextLines: [...], opcodes: [...], ... }
//
// $(