tags:

views:

86

answers:

1

I'm trying to collect some stats on some clicking events happening on my webpage.

I figured I would add an onmouse event to the links I want to track, and trigger an ajax call to my tracking php script.

What would be the most efficient way to do that, knowing that I don't expect anything in return, and that things should go on normally even if it fails?

I know there are some special HTTP calls when you don't expect any data back. What is it exactly? Does jQuery support it? What about my php script, should it return a special HTTP header?

Any advice to make this efficient is welcomed.

Thanks

Nathan

+4  A: 

You could send a 204 no content. Google seem to do it on their home page for exactly the same purpose for making the client look up a DNS entry faster.

See this SO question about how Google uses it: Google.com and clients1.google.com/generate_204

And the Status Code Definition sounds about right:

10.2.5 204 No Content

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

Pekka
good stuff. What about the jQuery Ajax call itself? Is GET the best there is? Or can we do a HEAD or something like that? Or is it worth it?
nute
Good question. I don't know 100% but a GET should be sufficient (I've never seen a HEAD call in Ajax). With a 204, the response body would be empty anyway.
Pekka