DEV Community

Cover image for How I built a zero-dependency habit timer that keeps working offline
LifeTimer
LifeTimer

Posted on

How I built a zero-dependency habit timer that keeps working offline

TL;DR: I rebuilt my habit timer as a zero-dependency PWA. No build step, no framework, no analytics SDK. This post covers the architecture, three bugs that cost me the most time, and what I would do differently. Drafted with AI assistance; I reviewed and edited every line.

I wanted a timer that still works on a train with no signal, starts instantly, and does not need an account. The simplest way to guarantee that was to remove the toolchain. The whole app is plain JavaScript, CSS, and HTML, served as static files.

What the app does

It tracks time per category, keeps a coin balance, and unlocks small hand-drawn icons as you use it. There are two mini games and a daily check-in. The data lives on the device; a sync service is optional and only used when you enable it.

That last sentence sounds simple. It took a while to get right.

The stack, or the lack of one

  • ES5 plus IIFEs and a single global namespace. No transpiler, no bundler.
  • localStorage for state, IndexedDB for binary blobs.
  • One service worker with a versioned cache name.
  • A small event bus so modules can react to changes without importing each other.

The best part is debugging. What you see in the editor is what the browser runs. The worst part is discipline: without a compiler, naming conventions and tests are all you have.

Three bugs worth writing down

1. The service worker ate my updates

I appended a version query string to CSS and JS, then wondered why users still saw the old interface. The old service worker stripped the query string before matching its cache. The fix was to make the cache name include a build stamp and to force one reload when a new controller takes over. Cache invalidation is not a detail you can add later.

2. Date keys must be local

I used UTC date strings for daily check-ins. A user just after midnight locally saw yesterday's button. I switched to a local date key, and the check-in logic became boring. Boring is good.

3. A flexbox ellipsis that refused to appear

A text label inside a column flex layout would not truncate. The parent had align-items: center, so the child had no width to shrink into. Setting align-items: stretch on the parent and max-width: 100% on the child fixed it. CSS specs are precise, but the symptom looks mysterious until you know where to look.

What I would do differently

I would write the smoke tests earlier. A small Node sandbox that loads the real source files caught more regressions than any amount of manual clicking. I would also keep a written list of files that must be updated together: source, tests, service worker asset list, and the HTML entry. After that, every release is a short checklist instead of a memory game.

Closed beta

I built this app. It is now in a 14-day Google Play closed beta. If you use an Android phone with the Play Store working, you can opt in, install it, and open it once a day. After the 14 days, you can claim a lifetime perk card free when the app launches.

Opt in: https://play.google.com/apps/testing/com.wjddj.lifetimer

Details in English and Chinese: https://life-timer-test.surge.sh

Privacy policy: https://ddj123.top/privacy.html

No review, screenshot, or survey is required from testers, and you can uninstall it any time.

What is the one thing that makes you keep a habit tracker installed after the first week? I would like to read your answers.

Top comments (0)