Unused AEM Assets Cleanup
Published
Using ACS AEM Commons
- Navigate to Tools > ACS AEM Commons > Managed Controlled Process.
- Click on Start Process.
- Select Renovator from the list of available processes.
- Renovator Process:
- Source: Path of the folder you want to check for unused assets.
- Destination: Path where assets will be copied. However, since we're only performing a Dry Run, the path will not have any effect.
- Make sure to check the Dry run checkbox, otherwise all the assets will be moved to the Destination folder.
- Detailed Report should be checked to view information such as the list of assets, the number of references, and the specific pages where each asset is referenced. Otherwise, the response will only include the total number of assets and how many are referenced on other pages.
- Click on Start to execute the Renovator process.
- Click on the View to view the report. You can also Download the report in Excel format for further analysis.
- The report will provide a list of all assets in the specified folder, along with the pages where they are referenced and the number of references. This information can be used to identify unused assets that can be safely deleted from the asset repository.If you look carefully at the report, you will see that the ALL REFERENCES column shows the number of references for each asset, while the REFERRED IN column shows the pages where the asset is referenced. Based on above report, 4 assets are not referenced on any page. You can safely delete these assets from the asset repository.
Bulk Asset Delete using Sling Servlet
- Create a Sling Servlet that accepts the Excel file as input.
- Use Apache POI to read Excel file and extract the list of unused assets. Based on your excel report, you can update index to read asset path and reference count. Apache POI included in AEM Jar by default so you don't need to add any additional dependencies.
- Use Sling Job to delete the assets in the background. This is important because deleting a large number of assets can take time and you don't want to block the request.
- Using RepoInit, Create a Service User and provide necessary permission to delete assets from the asset repository.
- Retrieve ResourceResolver using Service User mapping.
- Finally, delete the assets using ResourceResolver.