Technical Explanation
Here’s a detailed explanation of how this method works:- Initial Request: When a visitor accesses the site, the tracking script sends a request to the API server.
- Unique Visitor: If the user has not visited the site before, they will ping the server without a cached
If-Modified-Since
timestamp. The server then responds with aLast-Modified
header set to the current date. - Returning Visitor: If the user has visited the site before, their browser will include an
If-Modified-Since
header with the date of the lastLast-Modified
response when pinging the server. The server can then recognise that the visitor has visited the site before.
- Unique Visitor: If the user has not visited the site before, they will ping the server without a cached
Last-Modified
timestamp is reset every day to ensure that visitors are counted as unique each new day.
By using the Last-Modified
and If-Modified-Since
cache headers, we can determine if the visitor has visited the website before. This approach is simple, efficient, and preserves the anonymity of the visitor.