Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Queuing mechanism for server-side AJAX requests

I have been struggling with a situation on a site where users' clicks generate AJAX requests, e.g. with some visual effect when the response comes. It sometimes happens that the user doesn't wait until the request is done (although he sees a loading indicator) and starts clicking other elements like crazy. Because in principle I cannot and don't want to disable that possibility, I have tried (more or less successfully) to ensure that anytime a new request is fired, the previous one is aborted (client-side) and its handlers are no longer called - whichever request comes last wins.

Although somewhat successfull on client-side, I'm now wondering whether there is some way to simulate a similar behavior at the server. As I cannot really kill the previous request, only disconnect from it, it will still run to the end and consume valuable resources. If the user clicks on 20 elements, he will only see the result of the very last request, but there will still be 20 requests on the server wasting the CPU doing useless work.

Is there some way to implement a last-win strategy for multiple requests of the same resource in the ASP.NET / IIS ? I guess the requests are anyway internally queued, and what I would need is for the IIS when it tries to dequeue the next one, simply have a look whether there are some others and only serve the very last one from the same session.

like image 947
Tomas Vana Avatar asked Nov 15 '22 02:11

Tomas Vana


1 Answers

I know that in ASP on IIS you could test for isClientConnected and abort if client had disconnected.

I believe something similar would exist in most plattforms.

But I do not know how it works with ajax?

like image 107
David Mårtensson Avatar answered Dec 25 '22 12:12

David Mårtensson