XML Compression in WebPage

I am passing a large amount of XML from server to client, in my application (250K-500K each time).

How can I compress it on the server and unpack it on the client using standard JavaScript? Is it possible?

0


source to share


2 answers


First, swearing and possible workarounds. Secondly, a possible crazy solution.

Countdown

If you are sending 250k - 500k back and forth between client and server, you are doing it wrong. Take a look

  • Only requesting and sending the required information

  • If the information is in XML that doesn't change frequently, configure your web server to aggressively cache http for those requests. Also, consider sending "does not change frequently" down with an initial page request rather than grabbing it from the server.

  • Consider sending JSON instead of XML. JSON is less verbose than XML and usually takes up less space. If your client side code NEEDS an XML object, restore it from the loaded JSON.

  • If you are using apache, mod_deflate will gzip your data to the client, which can accept it. The last time I looked at the gzip encoding in IIS, it did it by zip and unzipping it to disk, which quickly became a high load throat (YMMV).



Crazy decision

If you are trying to use the compress-in-javascript algorithm, the LZ77 compression algorithm has been ported to most languages, including javascript .

Find similar code for your server platform, compile the XML and then feed it to the code in the link above. To avoid encoding issues, I would try to wrap the compressed data in XML or JSON when submitting.

Javascript compression performance will be slow .as.molasses, so I discourage that route.

+2


source


Is this type of HTTP transmitted?

The easiest way is to look at web server side compression.



XML Usually compresses very well.

+1


source







All Articles