I have this simple chat tool to keep the chat room updated:
setInterval (loadLog, 2500);
function loadLog(){
//Scroll height before the request
var oldScrollHeight = document.getElementById("chatMessages").scrollHeight - 20;
$.ajax({
url: "/includes/chat/log.html",
cache: false,
success: function(html){
//Insert chat log into the #chatMessages div
$("#chatMessages").html(html);
var newScrollHeight = document.getElementById("chatMessages").scrollHeight - 20;
if(newScrollHeight > oldScrollHeight){
//Autoscroll to bottom of div
$("#chatMessages").animate({scrollTop: newScrollHeight}, 'normal');
}
},
});
}
Reliably executes approximately every 2.5 seconds. However I want to save bandwidth so...
I change:
cache: false
to
cache: true
And now it does not reliably execute every 2.5 seconds. (maybe each subsequent request is taking longer than the previous? maybe not, its behavior is very odd)
My research has yielded nothing. Please help! <3