9

All modern browsers include gzip routines for exchanging compressed data with servers. Can anyone point me in the right direction for writing a Chrome extension that would allow Javascript to leverage this routine?

I would like to compress some data in Javascript before sending it to the server over a WebSocket, and Chrome's built in deflate routine would certainly be faster than anything I could write in Javascript.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
Brandon
  • 2,367
  • 26
  • 32
  • Interesting question. I wonder if this can be done on the transport layer. Is there a secure option for WebSockets (because SSL automatically compresses data)? – Thilo Jul 19 '12 at 03:19
  • Yes, according to http://www.html5rocks.com/en/tutorials/websockets/basics/#toc-gettingstarted if you open your socket with "wss://" as the protocol, it uses SSL. – Brandon Jul 19 '12 at 03:48
  • @Thilo: Are you sure that SSL compresses data? It *encrypts* the data but IMHO it doesn't compress "by itself". – Wladimir Palant Jul 19 '12 at 08:01
  • 3
    @Thilo: See http://www.belshe.com/2010/11/18/ssl-compression-and-you/ - SSL compression is almost never used, you would need SPDY to actually compress the data (which is supported by Chrome but the server has to support it as well). – Wladimir Palant Jul 19 '12 at 08:09

2 Answers2

4

If a javascript implementation isn't fast enough for you, you could use native client.

You would use some gzip library in c/c++, and write the glue code so javascript can call it through native client. It should be near or equal to the speed you would get from calling chrome's internal routine were that possible.

Esailija
  • 138,174
  • 23
  • 272
  • 326
3

Based on this answer to a Stack Overflow question, manually applying gzip to a WebSocket is completely unnecessary. As of version 19, Chrome will apparently compress WebSocket traffic automatically when the server supports it.

Community
  • 1
  • 1
Brandon
  • 2,367
  • 26
  • 32