how to deal with duplicate ajax request generated by page refresh during long polling

Now I met with a problem with using long polling, my situation is:

  1. The client will send ajax request to server for latest application
    data, the data is required to update web page.
  2. We don’t know when the data will change, so we can either choose to ask server periodically( traditional http polling ) or long
    polling. I used long polling to save resources.
  3. If an user visit the page, the request is sent to server immediately. And on the server side, it is hold until an event
    happen, then the data is returned.
  4. I am using java servlets on server side.

The problem is:

Suppose if a request from client A is under processing. There are two bad cases:

  1. The client refresh the page, then a new ajax request will be sent to the server. The the server might need to process many useless duplicate requests

  2. Then the client closed the page because of some
    reasons. How should I know the client has left and how to deal with
    the request.

How can I deal with these cases, the prevention is on the client side or server side.

Source: ajax

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.