0

On my site I show a huge numbered vehicle-paths. I get the coordinates via ajax, but sometimes its too slow because of the filesize. I want to compress it, its okay, but I can't uncompress it before I process the xml in javascript (with jQuery). Unfortunately I can't use php in the server side. Have somebody any idea?

Any help would be appreciated.

kree
  • 440
  • 1
  • 8
  • 26
  • Check out this answer http://stackoverflow.com/questions/2095697/unzip-files-using-javascript – Killrawr Feb 05 '13 at 12:03
  • Thanks, I checked it, but it isn't cross-browser solution. But I need something like this. – kree Feb 05 '13 at 12:22
  • 1
    Other solutions might be to send json (such as file path) with ajax to the server and have the server language unzip the file for you, and respond once its completed the task. – Killrawr Feb 05 '13 at 12:24
  • But I need to download a smaller size, not upload to compress. – kree Feb 05 '13 at 12:31
  • You can upload files with ajax, and then run server-process on that uploaded file. – Killrawr Feb 05 '13 at 12:34
  • I have the data on the server. The server compress it for the client side. I download it with ajax. I just want to download a smaller file, I don't want to upload anything. – kree Feb 05 '13 at 12:40

3 Answers3

1

There are some solutions already on Stackoverflow if you take a look at Unzipping files (contains a answer with zip.js). Here is a blog post about decompression with javascript cross-browser (includes IE) here.

Other solutions might be to send json (such as file path) with ajax to the server and have the server language unzip the file for you, and respond once its completed the task.

Not sure what server-side language you're using. But there are plenty of resources

Thanks, I checked it, but it isn't cross-browser solution. But I need something like this. kree

I'd recommend using some server-side language to process your zip files because it would be the easiest cross-browser solution.

Community
  • 1
  • 1
Killrawr
  • 3,744
  • 5
  • 32
  • 75
  • Thanks, I checked them. My problem with the zip.js is it isn't cross-browser. Unfortunately I have to work with IE7 too... And the post contain dead links. I should solve this problem on the client-side, our server can send only zipped files. Although, I thing I will force the competents to change it. – kree Feb 05 '13 at 12:34
  • Here is a blog post about decompression with javascript cross-browser (includes IE) http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/ – Killrawr Feb 05 '13 at 12:41
0

Compress it using HTTP compression and it will be completely transparent to your JavaScript.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
  • Yes, I should use it, but I can't set the Apache settings. I don't have rights to do it :/ – kree Feb 05 '13 at 12:27
  • @kree — so do it at the code level when generating your XML, or *get* the rights to do it (or get someone who does have the rights to make the change). – Quentin Feb 05 '13 at 13:36
  • Ok, but my task is find a solution in the client side... Not my idea :/ – kree Feb 05 '13 at 14:21
0

It's better to make this more transparent, like in PHP:

ob_start('ob_gz_handler');
header('Content-Type: application/json');
echo json_encode($data);

This will send the output using gzip compression and the browser will automatically decompress it for you.

Alternatively, the web server itself could take care of compressing the output generated by any server-side scripts.

Ja͢ck
  • 161,074
  • 33
  • 239
  • 294