0

I am working on a web portal where In my scenario there are big size JSON strings (1MB) which are sent by the server. We are using the WebSocket protocol. Obviously, it's taking a long time to load on client's browser.

I have tried Gzipping the JSON at the server end and try to decompress using Javascript. Compression is fine but I get some error while decompressing using JS. I used this library http://jsxgraph.uni-bayreuth.de/wp/2009/09/29/jsxcompressor-zlib-compressed-javascript-code/

Could anyone please suggest if there is another way?

P.S. As I am using WebSocket so I can't rely on browser's decompression.

4
  • Do you always see the error when decompressing? Or is it intermittent? If you're using gzip to compress on the server and zlib to decompress on the client (browser/JavaScript), that would be a problem. While the 2 are similar, they're not bitstream compatible. Commented Nov 28, 2013 at 6:08
  • I get error all the time. Even I doubt that Gzip and Zlib combination will work. Do you have any other idea/solution for this? Thanks for your reply! Commented Nov 28, 2013 at 7:27
  • How are you compressing the data on the server side? Dynamically through PHP? Some other language? What function are you calling to do the compression? Commented Nov 28, 2013 at 17:09
  • I am compressing in JAVA. I used the ByteArray and GzipOutputStream combination as per this post: stackoverflow.com/questions/16351668/… Commented Nov 29, 2013 at 4:16

2 Answers 2

1

Thanks for responding with clarifications. I think I see the problem now. Overall, remember that zlib != gzip, not exactly. Generally, gzip is zlib data but with some extra headers. JSXCompressor wants zlib data but you're sending gzip data from Java. To explain further:

On the page you linked to which describes JSXCompressor, the example server side code uses PHP's gzcompress function. From the documentation: "This function compress the given string using the ZLIB data format." (Emphasis theirs.) The documentation further advises using gzencode if gzip is truly desired (it's not, in this case).

Here's the documentation for Java's GZIPOutputStream class. Note that this class outputs data in gzip format. It looks like the solution is to climb one level higher in the class hierarchy and leverage the DeflaterOutputStream class.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mike! I changed the server side compression to use DeflaterOutputStream but still I am getting error while decompressing. I checked js and it is using some function such as .length, charAt() etc on the zipped content and that is why it is throwing error. The js file is min.js and I work mostly at server side so I do not know what is really wrong in js file.
0

I was not encoding(BAse64) the string after Gzipping it and that is why the js was complaining. After doing Base64 encoding its working fine even with GZIPOutputStream at Java end. I am using non-minimized version of the jsxcompressor from here:

http://sourceforge.net/apps/trac/jsxgraph/export/2808/trunk/JSXCompressor/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.