Deletes unused assets. Saves storage space.

Fund package maintenance!

Installs: 13 855

Dependents: 0

Suggesters: 0

Security: 0

Stars: 15

Watchers: 3

Forks: 4

Open Issues: 1


v3.0.0 2024-05-10 16:22 UTC

This package is auto-updated.

Last update: 2024-07-10 16:37:48 UTC


Statamic 3.0+ Latest Version on Packagist Downloads

Supports Statamic 3, 4 and 5.

Clean up unused images and assets from your Statamic site. Saves storage, keep things tidy.

The addon scans your entire content and users directory. If an asset is not referenced anywhere, it will be marked as unused. You can review the list of unused assets and delete them.

The addon is easy to configure. See the Configuration section below.


How to Install

You can search for this addon in the Tools > Addons section of the Statamic control panel and click install, or run the following command from your project root:

composer require swiftmade/statamic-clear-assets

How to Use

Simply run:

php please assets:clear


To publish the config file, use:

php artisan vendor:publish --tag=statamic-clear-assets-config

Here's all of the configuration options with their defaults:

return [

     * Where should we look to see if assets are still referenced or not?
     * If you're referencing assets elsewhere in your codebase, add those paths here.
     * All paths are relative to the base_path()
    'scan_folders' => [

     * All assets from these containers will be left alone.
     * You can see all your asset containers under content/assets folder.
    'ignore_containers' => [

     * If we come across these filenames, we'll just leave them alone.
     * You can use "*" as a wildcard. eg: "IMAGE*.jpg" will ignore IMAGE1.jpg IMAGE23.jpg etc...
    'ignore_filenames' => [

     * You might not want to delete very fresh assets, as perhaps you want to use them soon.
     * Use this config to only detect and delete files older than x days.
    'minimum_age_in_days' => 0,

Common Questions

It's deleting assets that I'm referencing in my antlers templates!

If you want to ignore the assets referenced in your views, add resources/views to the scan_folders config. Keep in mind that this will only work if the filename is mentioned verbatim in the code. If you are using variables or other logic to reference the asset, the addon might not be able to detect that the asset is being used.

How do I always keep PDF files?

Add *.pdf to the ignore_filenames config.

How do I always keep assets from a specific container?

Add the container's slug to the ignore_containers config.

How do I only delete assets older than 30 days?

Set minimum_age_in_days to 30 in the config.