A faster alternative to image beacons with 1x1 gif

This post is more than 18 months old. Since technology changes to rapidly, this content may be out of date (but that's not always the case). Please remember to verify any technical or programming information with the current release.

So it seems like a very common solution for tracking hit rates is the transparent 1x1 pixel gif. Load this and parse your access logs: requests logged.

The problem I have with this is two fold:

a) it sends a 1x1 gif’s worth of data to the server. This should exist - it could be possible for browsers to show a broken image if the gif doesn’t exist

b) it requires a full data connection and transmission to do something so simple.

Instead, lets use the HTTP Code 204: No Content

HTTP response code 204 stands for “no content”. This means that there will be no additional data processed, sent or displayed after the last blank line in the header of the request.

Let’s put this in practice:


var track = new Image();

And the corresponding image is sent.


var track = new Image();
track.src = "/track/this/page.php";


die(header("HTTP/1.1 204 No Content"));

(Note, this also could be done probably just with an apache configuration to not even invoke the PHP engine).

Return to All Posts