I transfer a fair amount of XML from the server to the client, in my application (250K-500K each time).
How can I compress it on the server, and decompress it on the client using standard JavaScript? Is it possible?
I transfer a fair amount of XML from the server to the client, in my application (250K-500K each time).
How can I compress it on the server, and decompress it on the client using standard JavaScript? Is it possible?
Is this HTTP type transfers?
The easiest way would be to look into compression at the web server side.
XML Usually compresses really well.
First, a scolding and possible workarounds. Second, a possible crazy solution.
If you're sending 250k - 500k back and forth between the client and server, you're doing it wrong. Look into
Only requesting and sending back the information you need
If there's information in the XML that doesn't change often, configure your web-server for aggressive http caching for these requests. Also, consider sending the "doesn't change often information" down with the initial page request instead of grabbing it from the server
Consider sending down JSON instead of XML. JSON is less verbose than XML and will usually take up less space. If your client-side code NEEDS an XML object, reconstruct it from the JSON you just downloaded.
If you're using apache, mod_deflate will gzip your data for client that can accept it. Last time I looked into gzip encoding on IIS it did it's zipping and unzipping on disk, which quickly became a bottle-neck in high load situations (YMMV)
If you're hell-bent on trying the compress-in-javascript route, the LZ77 compression algorithum has been ported to most languages, including javascript.
Find the analogous code for your server platform, compress the XML, and then feed it to the code found in the link above. To avoid encoding issues, I'd try wrapping the compressed data itself in either XML or JSON when sending it down.
Javascript compression performance is going to be slow.as.molasses, which is why I discourage this route.