admin管理员组文章数量:1302870
I am still new to Javascript. I have a situation where many users can send large JSON back to the server. In order to limit traffic, I would like to gzip them. Is this possible in Javascript? How can I can create a byte array from the string representation of the JSON? Thanks.
I am still new to Javascript. I have a situation where many users can send large JSON back to the server. In order to limit traffic, I would like to gzip them. Is this possible in Javascript? How can I can create a byte array from the string representation of the JSON? Thanks.
Share Improve this question edited Nov 18, 2011 at 0:40 Jérôme Verstrynge asked Nov 12, 2011 at 5:49 Jérôme VerstryngeJérôme Verstrynge 59.6k96 gold badges295 silver badges466 bronze badges2 Answers
Reset to default 3I know of no gzip implementations, but there are other pression methods at your disposal.
This will lzw-encode a string using JavaScript:
// lzw-encode a string
function lzw_encode(s) {
var dict = {};
var data = (s + "").split("");
var out = [];
var currChar;
var phrase = data[0];
var code = 256;
for (var i=1; i<data.length; i++) {
currChar=data[i];
if (dict[phrase + currChar] != null) {
phrase += currChar;
}
else {
out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
dict[phrase + currChar] = code;
code++;
phrase=currChar;
}
}
out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
for (var i=0; i<out.length; i++) {
out[i] = String.fromCharCode(out[i]);
}
return out.join("");
}
I believe so, here's a wikipedia article on the subject http://en.wikipedia/wiki/HTTP_pression
本文标签: ajaxHow to zipgzip user data in javascript before sending to the serverStack Overflow
版权声明:本文标题:ajax - How to zipgzip user data in javascript before sending to the server? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741727455a2394687.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论