I own a small messaging platform and I'm trying to make it live, so everything needs to work without any refresh. Messages are sent with Ajax and the procedure is refresh-free. I'm also trying to make sure that when Alice sends a message to Bob, Bob receives it (almost) immediately. For this reason, I'm refreshing the div containing all of the messages every second with this script:
<script>
$(document).ready(function() {
var pageRefresh = 1000;
setInterval(function() {
refresh();
}, pageRefresh);
});
function refresh() {
$("#messagesframe").load(" #messagesframe > *");
}
</script>
<div id="messagesframe">
<!-- messages displayed here! -->
</div>
This makes sure that every second the new messages are shown. I have a doubt, however, that this may slow down the application. I am asking you, thus, whether this doubt is well-founded or if this procedure is harmless. Any help is appreciated.
Note: I'm using PHP.