I’m developing an web application using asp.net mvc, and i need to do a stopwatch (chronometer) (with 30 seconds preprogrammed to start in a certain moment) on client-side using the time of the server, by the way, the client’s clock can’t be as the server’s clock. So, i’m using Jquery to call the server by JSon and get the time, but it’s very stress because each one second I call the server to get time, something like this:
$(function() {
GetTimeByServer();
});
function GetTimeByServer() {
$.getJSon('/Home/Time', null, function(result) {
if (result.SecondsPending < 30) {
// call another function to start an chronometer
} else {
window.SetTimeout(GetTimeByServer, 1000); //call again each 1 second!
}
});
}
It works fine, but when I have more than 3 or 4 call like this, the browser slowly but works! I’d like to know, how improve more performace in client side, or if is there any way to do this… is there any way to client listen the server like a “socket” to know if the chronometer should start…
PS: Sorry for my english!
thanks
Cheers
Felipe,
On page load get the server time and also the Client Side time. and use the two in reference to determine what the server time is on the server side without using AJAX call every time. Sorry for the excess of suedo code but it shouldnt be too hard.