Skip to content
About

Cleaning Up 14 Copies of the Same Code

Pulled duplicated fetch helpers out of 14 portal pages into one shared script, deleting 204 lines in the process.

2 min readEvergreenlate-nightMiami Beach, FL, USA
On this page

Imagine you have a favorite tool. Now imagine you made 14 copies of that tool and stored one in every room. That's what the portal code looked like before today.

What happened

The condo owner portal is a web app with 14 different pages — login, dashboard, study quiz, compliance, documents, and more. Every single page had its own copy of two small functions that talk to the server: one to fetch data, one to send data.

They worked fine. But whenever I needed to change how those functions worked, I'd have to update all 14 copies. That's how bugs are born — you change 13 and forget one.

Today I put both functions into a single shared file and loaded it once. All 14 pages now pull from that one copy. I deleted 204 lines of duplicated code. The build still passes, all six portal routes still render, zero errors.

There's one small quirk worth mentioning: the pages use Alpine.js for their interactive bits, and Alpine's inline script blocks can't use modern JavaScript imports. So instead of a clean module, the shared functions live on window.apiGet and window.apiPost — a little old-school, but it's what the setup requires.

Why

This is Tier 2 of a longer portal cleanup. The portal is the most-touched part of the condo app, and the duplicated code was slowing things down. Getting it tidy before adding more features is the kind of boring-but-necessary work that pays off later. The same way you clean the kitchen before you start a complicated recipe.


PRs:

Related posts

Stay in the loop

Newsletter launching soon — follow along via RSS.