MediumSquare
Programming

The Day I Deleted a 70KB Date Library and Nobody Noticed

The browser already ships a world-class date formatter. I just never bothered to look.

35

For four years our dashboard imported a full date library for exactly three things: showing a timestamp in the user's locale, printing '3 days ago', and formatting a month header. Seventy kilobytes, minified and gzipped, parsed on every cold load, for three strings.

Last month I removed it. The pull request was 140 lines, most of them deletions. QA filed zero bugs. That silence is the whole point of this post.

What the platform already gives you

The Intl namespace has been quietly excellent for years. Most of us learned dates before it was reliable and never updated our habits. Here is what replaced our three use cases:

const stamp = new Intl.DateTimeFormat(undefined, {
  dateStyle: 'medium',
  timeStyle: 'short'
});
stamp.format(order.createdAt);

const rel = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' });
rel.format(-3, 'day'); // '3 days ago'

Passing undefined as the locale means 'use whatever the user's browser says', which is exactly what we wanted all along. Our Italian and German users suddenly got their own month names, marzo and März instead of March. Nobody had asked for that, and three people emailed to say thank you.

Photo by 2H Media on Unsplash
Photo by 2H Media on Unsplash

The parts that were genuinely hard

I will not pretend it was free. Two things took real thought:

  • Relative time needs your own thresholds. RelativeTimeFormat formats a number and a unit; it does not decide whether 26 hours is '1 day' or 'yesterday'. I wrote a twelve-line helper that picks the unit.
  • Parsing is still your problem. Intl formats, it does not parse. Luckily our API already sent ISO strings, and new Date(iso) handles those consistently in every browser we support.

If your app parses free-form user input like 'next tuesday', keep a library. That is a real problem and someone has solved it better than you will on a Friday afternoon.

Photo by Kyrie kim on Unsplash
Photo by Kyrie kim on Unsplash

Why the silence matters

The thing I keep thinking about is that removing the dependency produced no visible change. No new feature, no redesign. Just a smaller bundle and a main thread that finished parsing about 40 milliseconds sooner on a mid-range Android phone.

That is what most performance work looks like. It is invisible when it succeeds, which is why it rarely gets prioritised. Nobody demos a deletion.

A small checklist before you reach for a package

  1. Search MDN for the verb you need: format, compare, segment, observe.
  2. Check whether the API is supported in the browsers your analytics actually show, not the ones you imagine.
  3. Write the twelve-line helper and see how it feels.
  4. Only then install something.

The browser is a much larger standard library than we give it credit for. Every so often, go read the manual.

Cover: Photo by Towfiqu barbhuiya on Unsplash.

35
3 people clapped
Written byMatteo Rossi

Frontend developer in Milan. Browsers, performance and the web platform.

More to read