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-Sincetimestamp. The server then responds with aLast-Modifiedheader set to the current date. - Returning Visitor: If the user has visited the site before, their browser will include an
If-Modified-Sinceheader with the date of the lastLast-Modifiedresponse 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.