My Javascript application is downloading quite a bit of data from the server and I was thinking that in addition to normal gzip that’s done by the server, I can encode the data in some binary format rather than textual JSON.
Is there a standard way of doing this?
Ideally it should be some small tool that can take a JSON text file and convert it to a generic binary format and a small Javascript library which decodes it.
Also, is there something special that needs to be done in XHR to pass binary data?
If gzip doesn’t compress well enough, chances are your binary format won’t either, especially if you wan’t to be able to decode it via javascript within a reasonable amount of time.
Remember that the unzipping when using gzip is done natively by the browser and is orders of magnitude faster than anything you can do in javascript.
If you feel that the JSON deserialization is too slow, because you are supporting older browsers like ie7 which doesn’t decode JSON natively but depends on
evalfor the job, consider going away from JSON to a custom encoding based on string splitting, which is much much faster to deserialize.For inspiration try to read this article:
http://code.flickr.com/blog/2009/03/18/building-fast-client-side-searches/