Delete unused assets in Statamic

We've published a Statamic add-on for you. It finds and deletes unused assets.
Ahmet Özışık · Founder · June 8th, 2022

At Swiftmade, we've grown quite fond of Statamic and now it's our go-to CMS whenever there's a project that calls for it.

One of our clients, Workland, asked our help for their website. They wanted a new website that is modern, fits their positioning in the market as a premium brand and most importantly loads fast.

After building it in Statamic from ground up and moving all of their Wordpress content and assets, there was one problem. The assets folder was huge. It contained close to a gigabyte worth of photos.

Obviously, not all of these images were being used. But which ones to delete?

Enter assets:clear addon

Looking for a solution to get rid of unusued assets, I've stumbled upon one add-on in Statamic's marketplace. To my dismay, it only supported Statamic 2.

So we've built our own for Statamic 3. It's a simple CLI tool.

It scans all of the assets. For each asset, it will then recursively search the contents folder. If none of the contents point to the asset, then it's marked for deletion.

Polishing it up

Shortly after publishing our addon, Erin Dalzell from Statamic community reached out and suggested some additional features like the ability to see which files will get deleted, and to control the deletion of files line by line. We quickly implemented those suggestions (thanks Erin) and released a new version.

Enjoy!

If you like this idea, go ahead and give our addon a try. More information and instructions can be found here:

Statamic Clear Assets Addon

You can also give a star to our Github repository: https://github.com/swiftmade/statamic-clear-assets

MORE FROM OUR BLOG