← cd ../blog

Why I still reach for vanilla JavaScript first

I use frameworks. I like frameworks. But my default move for a new feature is still a plain <script> tag.

The checklist

Before adding a dependency, I ask:

  1. Can the platform already do this?
  2. Will I still be maintaining this in three years?
  3. How many kilobytes am I paying for what I actually use?

Surprisingly often, the platform wins.

Example: a tiny accordion

document.querySelectorAll('[data-accordion] button').forEach((btn) => {
  btn.addEventListener('click', () => {
    const open = btn.getAttribute('aria-expanded') === 'true';
    btn.setAttribute('aria-expanded', String(!open));
    btn.nextElementSibling.hidden = open;
  });
});

Twelve lines, no build step, accessible by default. (Or just use <details> and write zero.)

When I do reach for more

The goal isn't purity. It's choosing the smallest tool that does the job well.