Menu

1 / 2

Building a Drift-Free, Zero-Dependency Cue Timer in a Single HTML File

DEV Community: html·Donovan Thomas Lafferty·5 days ago
#2i5vDU9h
#devto2#devto#dev#gain#timer
Long article (551 words) — no AI summary yet.
Reading 0:00
15s threshold

Most browser timers are way heavier than they need to be—wrapped in ad scripts, cookie banners, and frameworks just to count down five minutes. When I need a clean timer for rehearsal pacing, sprint blocks, or quick work intervals, I want something dark-mode, keyboard-first, and completely offline-capable.

So I put together Cue Timer in a single index.html page with zero dependencies and zero external audio assets.

1. Avoiding setInterval Drift

The classic trap with JavaScript timers is decrementing a counter inside setInterval(..., 1000) . Browser tabs throttle background intervals, so a 15-minute timer can easily drift by several seconds.

Instead of counting ticks, the timer records a target timestamp using performance.now() when you hit Start, and calculates the delta on every requestAnimationFrame :

function tick ( ) { remainingMs = endTime - performance .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.