Network difference between two lines in javascript

I have a web application in which the client-side editor edits really big text that is known on the server side.

The client may make any changes to this text.

What is the most efficient network efficient way to convey the difference in results as the server understands? Also, since this will happen on the client side (Javascript), I would also like it to be “fast” (or at least not noticeably slow)

Some scenarios:

  • User changes the ONE character
  • User changes several offers in random positions.
  • The user deletes everything and displays empty text.

I cannot use diff-like syntax, since it is not efficient on the network, it checks lines where examples 1 and 3 will give terrible differences (especially the last one, where the result will be larger than the old one).

Anyone have any experience with this? The user works on a really large dataset - about 3-5 MB of text, and downloading all the "new" content is a big no-no.

To be clear, I am looking for a “transfer protocol”; string comparison is not a problem.

+3
source share
5 answers

I am not very good at this topic, but I can point to an open source project (Apache License 2.0), which can be very useful.

Diff, Match Patch, , JavaScript, Google .

:

+3

, , , , ( ), , , , .

diff ( , " " ), , .

, , , . , - ; , .

. ed, diff -e . , ed. , , , , .

+1

, , : delete from X Y; X " ". X Y - ; Y - ; "" - . , diff, , , , , " ", .

, , , , - , D , , . , , ( ) , , , ( , , , , , ).

, , ( ) - , , /, .

+1

500 , , 500 , , , .

() , .

, , , .

0

- , , 500 , , - , -, . , , , - , .

Perhaps this is not possible in your situation, but if it is, I would have guessed that in the end there would have been much less problems in avoiding the problem in this way and just sending complete documents after editing.

0
source

Source: https://habr.com/ru/post/1720249/


All Articles