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() {
$.ajax({
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);
}
out.push(phrase);
currChar = phrase.charAt(0);
dict[code] = oldPhrase + currChar;
code++;
oldPhrase = phrase;
}
return out.join("");
}
The Gzip file it's avaiable here if anyone wants to try it: http://186.202.61.3/ale/Feijo.json.gz
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.
Thanks.