Interesting, Browser can now compress using pako

Zlib compression on Browser

Found open source js library that can be use to compress data inside browser. It seems cool. https://github.com/nodeca/pako

var pako = require('pako');

// Deflate
//
var input = new Uint8Array();  
//... fill input data here
var output = pako.deflate(input);

// Inflate (simple wrapper can throw exception on broken stream)
//
var compressed = new Uint8Array();  
//... fill data to uncompress here
try {  
  var result = pako.inflate(compressed);
} catch (err) {
  console.log(err);
}

//
// Alternate interface for chunking & without exceptions
//

var inflator = new pako.Inflate();

inflator.push(chunk1, false);  
inflator.push(chunk2, false);  
...
inflator.push(chunkN, true); // true -> last chunk

if (inflator.err) {  
  console.log(inflator.msg);
}

var output = inflator.result;  

Sometime you can wish to work with strings. For example, to send big objects as json to server. Pako detects input data type. You can force output to be string with option { to: 'string' }.

var pako = require('pako');

var test = { my: 'super', puper: [456, 567], awesome: 'pako' };

var binaryString = pako.deflate(JSON.stringify(test), { to: 'string' });

//
// Here you can do base64 encode, make xhr requests and so on.
//

var restored = JSON.parse(pako.inflate(binaryString, { to: 'string' }));