Clean Up Unused Assets in public/ with a Node.js Script
DRAFT 01
Clean Up Unused Assets in public/ with a Node.js Script
Scan your public folder, find files nothing references, and delete them safely before deploy.
Context
Over time, web projects often accumulate unused files in the public/ directory—images, icons, test files, and more. These unused assets increase build size, slow down deployments, and clutter your repo.
To solve this, I created a Node.js script that scans the public/ folder, checks which assets are actually referenced in the project, and gives you the option to delete the unused ones.
How it works
Recursively collects all files in the public/ directory.
Scans your entire project (excluding folders like node_modules, .git, dist, etc.).
Supports common frontend file extensions: .js, .ts, .vue, .html, .css, and more.
Checks whether each public file is referenced anywhere in your codebase.
Prompts you before deleting any files.
When to use this
Before deployment to reduce bundle size
During codebase cleanups or refactoring
To maintain a tidy and optimized public/ folder
This script is especially useful for teams working on large frontend projects, or those who've gone through multiple redesigns where assets were left behind.
The script
Install readline-sync if you want interactive confirmation:
npminstallreadline-sync
Save the following as something like scripts/find-unused-public-assets.mjs and run it from your project root:
The script lists files under public/ that never appear in your source, then waits for y before deleting anything.
Conclusion
Keeping public/ lean is low effort with high payoff: smaller deploys, less noise in reviews, and fewer “is this file still used?” moments. Run the scan before a release or after a redesign and treat the prompt as the final safety check.