JSON.stringify is obviously not very space efficient. For example, [123456789,123456789] occupy 20+ bytes when it could need just around 5. Does websocket compress its JSONs
WebSocket is, at its heart, just a set of framing for TEXT or BINARY data.
It performs no compression on its own.
However, the WebSocket spec allows for Extensions, and there have been a variety of compression extensions in the wild (the formalized specs for one of these is finalized).
As of today (August 2018) the accepted compression spec is permessage-deflate
.
Some of the extensions seen in the wild:
x-webkit-deflate-frame
- an early proposed compression that compresses each raw websocket data frame. Seen in use by Chrome and Safari. (now deprecated in Chrome and Safari)Of note, the permessage-deflate
extension is the first in a line of PMCE (Per-Message Compression Extensions) that will eventually include other compression schemes (ones being discussed are permessage-bzip2
, permessage-lz4
, and permessage-snappy
)