Compressed Ajax Communication: Ajaxの通信を圧縮

全面的に
» 高度な JavaScript 技集
のコードに頼っています。(このサイトはスゴイです。)

AjaxでServer-Client間の通信にzip圧縮をかけてみました。

サーバ側で圧縮(PHP):

echo base64_encode(gzdeflate($buf, 9));

クライアント側で解凍(JavaScript):

var data = utf8to16(zip_inflate(base64decode(req.responseText)));

CPUのコストはかかりますがデータの転送量を減らせるので、JSONで大量のデータをやり取りする時に使えると思われます。クライアント側で圧縮も可能なのでPOSTも可。base64_encode/decodeはプレインテキストにするために必要。

demo(alertが出ます)

This entry was posted in つくる. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Page optimized by WP Minify WordPress Plugin