3 JavaScript Performance Mistakes That Cost You Users (And How to Fix Them)
Your app works on your MacBook Pro with 32GB RAM and fiber internet. But for a user on a $120 Android phone with 2GB RAM and spotty 3G, it is unusable.
Performance is not a luxury. It is accessibility. Here are three mistakes I see in almost every codebase I audit, and the exact fixes that work.
Mistake 1: Loading Everything Up Front
// What most apps do import { Chart, Map, Editor, VideoPlayer } from './heavy-components'; Even if only 10% of users open the dashboard with the chart, everyone pays the download and parse cost.
The fix: Route-level code splitting
import { lazy, Suspense } from 'react'; const Chart = lazy(() => import('./Chart')); const Map = lazy(() => import('./Map')); function Dashboard() { return ( <Suspense fallback={<Spinner />}> <Chart /> </Suspense> ); } Split at the route level, not the component level. Too many small chunks create network waterfalls. Aim for 3–5 chunks per route.
Mistake 2: Trusting Your Build Output
Vite reports "184KB." You celebrate. But the real transfer size is 1.2MB because:
- You imported all of
lodashinstead oflodash/debounce - A transitive dependency pulled in 3 versions of
tslib - An icon library shipped 4,000 SVGs you do not use
The fix: Audit before you optimize
# See what is actually in your bundle npx vite-bundle-visualizer # Find duplicate dependencies npm ls some-library npm dedupe Replace barrel imports with direct paths:
// Bad import { Button, Modal } from 'huge-ui-lib'; // Good import Button from 'huge-ui-lib/Button'; import Modal from 'huge-ui-lib/Modal'; One audit I ran found moment (65KB), dayjs (8KB), and date-fns (12KB) all in the same app. Pick one date library. Delete the others.
Mistake 3: Blocking the Main Thread
Heavy computation freezes the UI. Users cannot scroll, click, or type while JavaScript runs.
// This blocks for 2+ seconds on large datasets const result = massiveArray.map(transform).filter(check).sort(compare); The fix: Yield to the browser
For data processing, use requestIdleCallback or chunk the work:
async function processInChunks(items, chunkSize = 100) { const results = []; for (let i = 0; i < items.length; i += chunkSize) { const chunk = items.slice(i, i + chunkSize); results.push(...chunk.map(transform)); // Yield control back to the browser await new Promise(resolve => setTimeout(resolve, 0)); } return results; } For truly heavy work, use Web Workers. They run on a separate thread and do not block the UI.
The 80/20 of Frontend Performance
You do not need a perfect Lighthouse score. You need a usable experience for real users on real devices.
- Split your code at the route level
- Audit your bundle and remove dead weight
- Yield the main thread during heavy work
Do these three things, and you will outperform 90% of web apps without touching a caching strategy or CDN config.
What performance mistake have you fixed that had the biggest impact? Drop it in the comments.