DEV Community

Wordlyo
Wordlyo

Posted on Originally published at wordlyo.com

I Built a Word Counter That Runs 100% in Your Browser — Here's What I Learned

I recently built Wordlyo, a free word counter, as part of a small suite of text tools. No backend, no database, no tracking — everything runs in vanilla JavaScript in the browser. It was a small project, but it taught me a few things about text processing that I think are worth sharing.

1. Counting words is trickier than split(' ')

The naive approach — text.split(' ').length — breaks on multiple spaces, tabs, newlines, and leading/trailing whitespace. The robust version is boring but correct:

function countWords(text) {
  const words = text.trim().split(/\s+/);
  return text.trim() === '' ? 0 : words.length;
}
Enter fullscreen mode Exit fullscreen mode

\s+ handles spaces, tabs, and newlines in one pass. The empty-string guard matters: ''.trim().split(/\s+/) returns [''], which would count as one phantom word.

2. Real-time counting needs debouncing (or doesn't)

Conventional wisdom says debounce input handlers. But for a word counter, the operation is O(n) on the text length and browsers handle it in well under a millisecond for any realistic paste. I update on every input event with no debounce, and it stays smooth even with 100k+ words. The lesson: measure before you optimize. performance.now() around your handler will tell you the truth in ten seconds.

3. Reading-time estimates are just division

A useful extra: estimated reading time. Average adult reading speed is around 200–250 words per minute. So:

const minutes = wordCount / 225;
Enter fullscreen mode Exit fullscreen mode

Display it as "X min read" and round up. Users love this more than the raw count — it answers "how long will this take me?" instead of "how many tokens are here?"

4. Speaking time is a different constant

For speech scripts, conversational pace is roughly 130–150 words per minute (slower than reading). I added a speaking-time estimate using 140 wpm after writing a companion guide on how many words fit in a 5-minute speech. Same division, different constant, completely different use case — presenters and students.

5. Privacy is a feature you get for free

Because everything runs client-side, there's nothing to leak. No text ever leaves the device. I put "runs entirely in your browser" front and center, and it's the thing users mention most. In an era of cloud-everything, local-first tools feel refreshingly honest — and they're simpler to build and host (it's just static files).

6. Character counting has real-world tables

A character counter becomes ten times more useful with platform limit tables next to it: tweet/X post limits, meta description ranges, SMS segments. Reference data turns a dumb counter into a tool people bookmark.

Takeaway

Small utility projects are underrated learning vehicles. You touch regex, performance measurement, UX copy, and SEO fundamentals — all in a weekend-sized project. If you've been meaning to build something, a text tool is a great start: the problem space is well-defined, the feedback loop is instant, and real people will actually use it.

The full tool is live at wordlyo.com/word-counter if you want to poke at it. Happy building.

Top comments (0)