0

I have a simple text editor and want to implement auto save so that any time a change is made to the text, it is immediately sent to the server.

There are two ways to do this:

  1. Open a socket connection and send changes through the socket every second.
  2. Set a 750ms idle keyboard change timer that sends changes any time the user has stopped typing for 750ms.

I understand websockets are appropriate when you don't want to poll to check the server for new data. But is it also appropriate for when you want to constantly send data to the server?

Is 1 request/user/second on a web socket more performant in general than 1 request/user/second on a regular http connection?

Update:

For the record, I looked into Google Docs and it seems to use post requests and not websockets for autosave:

enter image description here

It fires with about a 150ms keyboard idle timer, and only sends incremental changes.

Snowman
  • 31,411
  • 46
  • 180
  • 303

1 Answers1

0

WebSocket is entirely appropriate for permanently sending small amounts of data to the server.

There are two main advantages:

You do not need to establish a connection each time you send data, which makes things faster (though this may not be all that important for your application).

You save on message size, since the HTTP headers are much larger than those of WebSocket messages.

(For more on this see this thorough StackOverflow answer.

Community
  • 1
  • 1
gzost
  • 2,375
  • 1
  • 18
  • 25