Mark
Mark

Reputation: 5653

Compress an XML file with javascript?

I have found the DIY Map.. an excellent map tool if you are ever looking for one. Aside from how fantastic it is... the associated XML file can get fairly large (it contains map setting, country names etc). I was wondering if it were possible to compress it and have javascript uncompress it on the users side....

There is a lot of repetition in there a lot of tags that I was thinking could be swapped with place holders and then replaced by the javascript...

or should I just rely on gzip to do that for me?

Upvotes: 3

Views: 2129

Answers (4)

Tendayi Mawushe
Tendayi Mawushe

Reputation: 26118

GZip Compression is widely supported by web-servers and will give you a significant compression and therefore download speed.

Implementing your own scheme in JavaScript will be slow due to the extra string processing you will be doing on the client before you actually process your XML file.

This extra code will also be adding the possibility of additional bugs in your application if the search and replace matches things you do not expect. So would recommend you not add the extra engineering effort until you are certain it is required.

Upvotes: 0

jeffreyveon
jeffreyveon

Reputation: 13830

JS is very slow. GZIP is definitely the way to go.

Upvotes: 1

Rubens Farias
Rubens Farias

Reputation: 57946

You could enable HTTP compression into your web server and let your browser to uncompress it.

You shouldn't do that in javascript;

Upvotes: 1

Christoph
Christoph

Reputation: 169583

Store a pre-compressed file alongside the raw file so the compression doesn't have to happen at runtime. Implementing your own compression scheme will most likely not gain you anything (as long as you don't drop actual data) and will hurt client-side performance.

Upvotes: 0

Related Questions