Is – See here.$("*").click(function(){...}) considered expensive?
How about sending an ajax request on every click?
Will it cause a noticeable (perf?) problem for normal users? The app is not a game where you need to rapidly click stuff … just a normal web app. Clicks are, I would imagine, relatively rare.
Take Stack Overflow as an example site – if this was done on SO, would it be expensive?
Note – from the linked question, I get the notiion that $("*").click() would have horrible perf on its own, at least on some browsers. Is there a better technique to still do what I want (send an ajax request on every click), without being a perf hog? Is live() the answer?
Note – I’m focusing on the client, because I am not expecting a tremendous number of concurrent users. I believe the server can handle it.
If you want to catch clicks everywhere, you should use the
delegatemethod instead of binding all elements:This will bind a single event handler on the body element and handle events when they bubble up from the elements that are clicked on.
Sending an AJAX request on every click would not affect the browser much, but it might be heavy on the server if you have a lot of users. Also, if someone clicks several times in a row, the requests would queue up on the server, and it would take a while for all the responses to get back to the browser.