Today I was trying to decide how to set a header or a cookie so that my stat tracking tool could ignore my own traffic. When I’m working on a website I’ll load that site over and over again. I’d rather those impression don’t increase my site statistics.
After looking at several options, I decided a cookie might be the easiest way to go.
With that decision out of the way, I wanted to set it using the most strait-forward code I could think of. A single line with a hard-coded date seemed pretty simple.
That got me thinking about when it should expire. I’d rather not set this very often so I thought a year out at minimum. Then I asked an AI and it suggested the year 9999. That seems a little too far.
Well, there’s a morbid thought.
I think it’s as good a date as any, so I took a guess at my life expectancy. I hope I’ll live to around 85, under the best conditions. People live longer than that, sure, but I figure it’s a safe bet.
So, I grabbed my phone, opened the calculator, and figured out the year I’ll turn 85. I decided to set the cookie to expire on my birthday that year.
document.cookie = "myCookie=value; path=/; expires=Thu, 06 Apr 2061 00:00:00 GMT";
Ladies and Gentlemen, that puts the life I have left into a bit of perspective, doesn’t it?
Written by Joel Dare on March 22, 2025 or 36 years before my expiration date.
Get a monthly digest of what I'm up to.