How ajax event that occurs every one second affect the web page performance?
Asked by
Ranimi23 (
1917)
June 23rd, 2010
Is it really bad to do this?
Will it kill the server?
Observing members:
0
Composing members:
0
7 Answers
That’s what the fluther chat does.
I checked with Fiddler, in Fluther it is happening every 5 seconds.
I think it largely depends on what the script is doing as well as the client’s browser. If the ajax event is pinging the database, you could see a pretty large hit on db performance. As far as browsers, IE is probably the slowest of all but as long as you’re not doing crazy animations based on the result, you should be okay there. You might also want to consider that the ajax response can take longer than 1 second—in which case you’d be getting pretty poor performance. I’d set it up so that once you call the script, it’s stops repeating until the response is returned.
Hi @jpwilson25 Thank you for the answer.
How can I stop the script until the response is returned?
I’m not going to DB with this call, I am running a small code in C# that set the current time in a Label control. No animation or DB connection.
It looks like it’s currently every 3 seconds: http://michelangelo.fluther.com/templates/fluther/chat/room.v01265.js
Blocking until you get a response might make performance poor. If you just want the current time, you might be able to get away with running that all on the client’s side, no ajax calls needed.
(What is a “label control”? Is that a .NET thing?)
Actually, this is not the only thing I am trying to update with AJAX.
I am using .NET server control with JavaScript on the client, but haven’t figure it out how JS can talk with the server controls.
I just did something like this the other day using an UpdatePanel with an async postback trigger. There are several ways of achieving the same result but this method caused the least amount of grief and was pretty simple. The last link on this page should get you started.
You might also look into ASP.NET AJAX which I believe has a Timer control that can be integrated with an UpdatePanel. In fact, I’m pretty sure you can use System.Timers.Timer in .NET as-is… you’ll just run into problems when trying to do too much with it.
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.