NOTICE: I replaced my polling system with
websockets
but I still want to know the answer to my questions above.
I'm trying to reduce an AJAX request of a traditional-polling message system, but I don't know how to get it:
$chatbox = $("#chatbox");
setInterval(function(){
// I send the sha1 of the chatbox html content to verify changes.
$.post("post.php", {checksum: hex_sha1($chatbox.html())}, function (data, status) {
switch (status) {
case "success":
// If version of "post.php" checksum is different than mine (there are changes) data isn't empty; I assign data as the new content of the chatbox.
if(data){
$chatbox.html(data);
$chatbox.scrollTop($chatbox[0].scrollHeight);
}
break;
default:
$chatbox.html('Connection error...');
break;
}
});
}, 1000);
Well, As you see I use an setInterval()
with 1000
miliseconds as parameter and thanks to the SHA1
checksum system I can reduce the size of all AJAX response to 343 B
(except when "post.php" returns some new message, obviously)
Questions:
Why all my AJAX requests have ever the same size (
343 B)
even though I change the SHA1 (20 B
) hash to MD5 (16 B
)?My checksum variable (SHA1) occuppies
20 B
: Where do the remaining323 B
?Could I reduce more the AJAX request size? How?
NOTE:
hex_sha1()
is a implementation of SHA1 algorithm for Javascript: http://pajhome.org.uk/crypt/md5/sha1.html
NOTE 2:
Unfortunately I can't use an Server-Push Technique like
node.js
. I can only use Javascript (client-side) and PHP.
websockets
are not supported by all browsers yet. I'm wrong? – Delaunaywebsockets
as answer, please? (also I want to Know if is possible to reduce the AJAX request size) – Delaunay