开发者

Compress an XML file with javascript?

开发者 https://www.devze.com 2022-12-17 04:18 出处:网络
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

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?


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


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

You shouldn't do that in javascript;


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消