I was recently brought a challenge from a friend. Thought I’d share it here because I have no good solution.
Say I need a visitor hits count for my website, the count would permanently increase on every visit.
The Problem
It is considered bad practice to change the server state with GET requests. And since I’d like to keep count of the number of users that entered my website, I’ll have to store the state somehow.
How would I approach this? Should I break that practice and change the server on GET requests? Or is there some more elaborate scheme I can pull off?
The assertion you’re making is generally true. But here, you want precisely to track if someone made a GET request. So doing this treatment on such requests makes sense!
It’s just a bit tricky when using in combination with a caching mechanism. Because the part where you count the visitor can’t be in cache, you always need server-side to track the count.
Other solutions include:
[edit] I particularly like the tracking image. Makes both solutions easier.