How do I remove unused code?
Last checked 31 Aug 2026
Short answer
Ask Lovable to search for unused components, imports and dependencies, or run a tool like ts-prune/depcheck via the terminal, then remove what's confirmed unused and re-test.
Why it matters
Unused code adds to bundle size (slower initial load), clutters the codebase for future edits, and makes it harder for Lovable's AI to reason about your app when you ask for changes.
Ways to find it
- Ask Lovable directly:
Scan the project for components, functions and imports that are defined but never used, and list them without deleting anything yet.
- Dependency check. Unused npm packages still get bundled or at least slow installs. If you have terminal/Dev Mode access,
npx depchecklists dependencies that nothing imports. - Dead export check.
npx ts-prune(for TypeScript projects) lists exported symbols nothing else imports. - Route/page audit. Pages built during earlier iterations but no longer linked from navigation are easy to miss — check your router configuration for orphaned routes.
Process
- Generate the list of candidates (above) rather than deleting on sight.
- Confirm each one really is unused — search-based tools sometimes miss dynamic imports.
- Remove in small batches and re-test the app (or ask Lovable to do it) after each batch.
- Commit via Git sync before a big cleanup so you can revert if something breaks.
What usually goes wrong
Deleting a component that's still referenced by a dynamic import or a string-based route breaks the build in a way that's hard to trace. Use Version history to roll back a bad cleanup, and prefer small, verifiable batches over one large deletion pass. This pairs well with /questions/how-do-i-audit-a-lovable-project-s-performance as part of a general clean-up before launch.
Was this answer helpful?
Related questions
- AnswerWhy is my database making so many requests?Usually a component is re-fetching data on every render, a page is running the same query multiple times, or you're fetching entire tables instead of what's actually needed — ask Lovable to audit data-fetching patterns.
- AnswerHow do I improve Core Web Vitals?Focus on the three metrics Google measures — LCP (loading), INP (interactivity), and CLS (visual stability) — and fix the specific one flagged as poor, usually starting with images for LCP.
- AnswerHow do I lazy-load images?Ask Lovable to add native lazy-loading to images below the fold while keeping the hero/first-visible image loading eagerly, so visitors aren't downloading offscreen images before they're needed.
- AnswerHow do I reduce unnecessary database calls?Fetch only what a page needs, cache results, batch requests, and let Postgres do filtering instead of pulling whole tables into the client.