Hi everybody.

I'm building an site that will load a bunch of overlays into Google Maps. The overlays are static and already in JSON format to be loaded with AJAX.
This all works fine, ajax request, json parse, adding overlay.

But the json files are quite big, the largest has almost 5mb. So I Gziped it, and the size drop to about 2mb.

The problem is loading the GZip file with AJAX. I can't make it work.

For what I readed, the browser that should decompress the gzip file, but it ain't happening.
So I tried to use a function that I found on the web, but it ain't working neither.

This is my code till now:

    function testGZip() {
            url: "Feijo.json.gz",
            success: function (result) {
                var decoded = lzw_decode(result);
                var object = JSON.parse(str);

    // Decompress an LZW-encoded string
    // Code From http://jsolait.net/
    function lzw_decode(s) {
        var dict = {};
        var data = (s + "").split("");
        var currChar = data[0];
        var oldPhrase = currChar;
        var out = [currChar];
        var code = 256;
        var phrase;
        for (var i = 1; i < data.length; i++) {
            var currCode = data[i].charCodeAt(0);
            if (currCode < 256) {
                phrase = data[i];
            else {
                phrase = dict[currCode] ? dict[currCode] : (oldPhrase + currChar);
            currChar = phrase.charAt(0);
            dict[code] = oldPhrase + currChar;
            oldPhrase = phrase;
        return out.join("");

The Gzip file it's avaiable here if anyone wants to try it:

I'm using third-part libs:

  • Jquery 1.7
  • JSON 2

Obs.: The problem is not with the JSON, it's decoding the GZip.

Any help is appreciated.


Edited by mike_2000_17: Fixed formatting

4 Years
Discussion Span
Last Post by AleMonteiro

Have you tried this code with something much simpler? This snippet is mentioned on SO, the drawbacks have to do with some unicode characters apparently.


No, I didn't. Since those are the files that I need to make it work, I gone right into it.

What did you mean by SO, sorry but I didn't undestand the abreviation.

Any way, I'll make some tests with simple text and post back the results.


Oh right, now I get it.

So, I did a couple of tests using simple text files and none worked. I try letting the broswer do the job, tried with the code posted and also with a lib called JSXCompressor.

So I'm thinking that the problem may be in the gzip file. I'm currently ziping with GZip for windows.

Maybe I should implement something in the server side to zip the files instead of using a third part software.

Any thoughts on good compression algorithms?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.