When I first build my browser based game I use JSON as the data-interchange protocol. But then I realize the data in JSON object is too big for transmission. Although JSON serializaiton and deserialization may be the fastest because they are optimized for V8 engine, but NO JSON.
Then I have switched to using a 3rd party protocol or specifically MessagePack protocol as the implementation. I guess using protobuf or other 3rd party protocols give similar result. This binary data-interchange protocol reduce much of the traffic but I realize I am still building an Object before encoding into a binary ArrayBuffer. It seems I can just convert the data directly into TypedArray and send them as binary data without using an object, and that will also eliminate the property names in the objects, saving a few bytes for each message. If the message contains a list of objects it can save more space. This would look like my own custom binary data-interchange protocol which doesn't even need to involve encoding and decoding via MessagePack protocol.
I hope my custom binary data-interchange protocol is framework/language independent so I can implement it in different backend and frontend, not limited to Javascript. But as I have little experience with this before, I hope to get some feedback here. Using a 3rd party library/protocol may give me confidence as it is being used by many projects and the failure rate is low. But I can also get rid of the 3rd party protocol and use my own, which looks much cleaner and I know all the details of the protocol.
At the end of the day my protocol may look something like this:
(Using '|' to separate each type of data but the '|' doesn't put into data transmission as I know how it is organized)
TIMESTAMP|MESSAGE_TYPE|PLAYER_ID|PLAYER_X|PLAYER_Y|PLAYER_ROTATION ...