0

We would like to check every 3 seconds if there are any updates in our database, using jquery $.ajax. Technology is clear but are there any reasons why not to fire so many ajax calls? (browser, cache, performance, etc.). The web application is running for round about 10 hrs per day on every client. We are using Firefox.

Thomas1703
  • 1,152
  • 5
  • 16
  • 33
  • You could add some precision to your question to get more precise answer. For instance telling what is running on the server side and what is the purpose of this application.. – Sami Apr 06 '13 at 18:37

4 Answers4

1

Ajax calls has implications not on client side(Browser,...) but on the server side. For example, every ajax call is a hit on server. ie. more bandwidth consumption, no of server request hit increases which in turn increases server load etc etc. Ajax call is actually meant to increase client friendliness at the cost of Server side implications.

Regards, Ravi

Ravi Trivedi
  • 2,340
  • 2
  • 14
  • 20
1

You should think carefully before implementing infinite repeating AJAX calls with an arbitrary delay between them. How did you come up with 3 seconds? If you're going to be polling your server in this way, you need to reduce the frequency of requests to as low a number as possible. Here are some things to think about:

  • Is the data you're fetching really going to change that often?
  • Can your server handle a request every 3 seconds, how long does the operation take for a single request?
  • Could you increase the delay after inactivity or guess based on previous server responses how long the next delay should be?
  • Can you stop the polling completely when the window loses focus, and restart it when it's in the foreground again.
  • If a user opens the same page in a website 10 times, your server should recognise this and throttle its responses, either using a cookie with a unique value in it (recommended) or based on the client IP address.

Above all, instead of polling, consider using HTML 5 web sockets to "push" data to the client - most modern browsers support this. Several frameworks are available that will fall back to polling if web sockets are not available - one excellent .NET example is SignalR.

Community
  • 1
  • 1
greg84
  • 7,541
  • 3
  • 36
  • 45
0

I've seen a lot of application making request each 5sec or so, for instance a remote control (web player) or a chat. So that should not be a problem for the browser to do so.

What would be a good practice is to wait an answer before making a new request, that means not firing the requests with a setInterval for instance. (In the case the user lose its connection that would prevent opening too much connections). Also verifying that all the calculations associated with an answer are done when receiving the next answer.

And if you have access to that in the server side, configure you server to set http headers Connection: Keep-Alive, so you won't add to much TCP overhead to each of your requests. That could speed up small requests a lot.

The last point I see is of course verifying that you server is able to answer that much request.

Sami
  • 648
  • 8
  • 25
0

You are looking for any changes after each 3sec , In this way the traffic would be increased as you fetching data after short duration and continuously . It may also continuous increase the memory usage on browser side . As you need to check any update done in the database , you can go for any other alternatives like Sheepjax , Comet or SignalR . (SignalR generally broadcast the data to all users and comet needs license ) . Hope this may help you .

user1260967
  • 89
  • 1
  • 2
  • 14