Is there a Javascript compression and PHP/Ruby decompression library for strings? I need it because I need to send a very long text string using Ajax on a slow upload link to a web server which uses PHP/Ruby as server-side language.
var x = $('#sources').html();
// a very-very long text
var xo = x, o = {};
if(x.length>512*1024) {
x = compress(x);
o.c = 1;
}
o.x = x;
$.post('target.php',o,function(res){alert(res==xo)});
On server side (for example, PHP):
<?php
if(isset($_POST['c']) && $_POST['c']=='1') {
$x = decompress($_POST['x']);
} else {
$x = $_POST['x'];
}
echo $x;