Why Timers Jump When a Tab Sleeps
Browsers slow down background tabs on purpose. Good timers do not count ticks — they subtract timestamps.
Browsers throttle background tabs
To save battery, browsers slow JavaScript timers in tabs you are not looking at, sometimes to once a minute. A timer built by subtracting one every second will therefore fall behind: leave it for ten minutes and it may show ten minutes more than it should.
The timestamp fix
A reliable timer stores the target moment — an end timestamp — and on every visible tick computes target minus now. When you return to the tab, the display corrects itself in one jump, because the arithmetic never depended on how many ticks actually ran. The jump is not a bug; it is the correction.
What to look for
Pause and resume should work the same way: pausing stores the remaining time, and resuming rebuilds a new end timestamp from now plus that remainder. If a timer drifts after a tab sleeps, it is counting ticks. If it jumps once and is then correct, it is doing the honest thing.
More posts
AM, PM and Midnight, Explained Plainly
Why 12 AM is midnight, why 12 PM is noon, and how to avoid the most common clock mix-up.
Daylight Saving and Time Zone Conversion
Why the gap between two cities changes through the year, and how converters handle DST gaps and repeats.
Leap Days, Birthdays and Age
What happens to a 29 February birthday in an ordinary year, and how age arithmetic handles it.
Month-End Overflow: Why January 31 Plus One Month Is Tricky
Adding months is not like adding days. Here is the clamping rule, and why it is the honest choice.
Counting Days: Inclusive or Exclusive?
Two honest answers to how many days until a date, and how to tell which one you are reading.