问题
I'm using the asset pipeline in Rails and we have many haml partials that some are probably not used, along with unused images.
How do you work out if an asset is not being used, e.g. images, haml, etc.? Is there an automated way to find out?
回答1:
I found some links but haven't tried them yet. I will report back when I get a chance to try them out:
discover-unused-partials
A script to help you finding out unused partials. Good for big projects or projects under heavy refactoring. Covers Haml and ERB.
deadweight
Deadweight is a CSS coverage tool. Given a set of stylesheets and a set of URLs, it determines which selectors are actually used and reports which can be "safely" deleted.
Searching production.log
There is a handy blog post called Removing deadweight, describing how to grep through the production log and a script to find and delete assets that have not been seen.
The grep command they use is:
grep -Eo ‘GET /(.*(.gif|.jpg|.jpeg|.png|.css|.js))[ \?]’ access.log > ~/assets.txt
来源:https://stackoverflow.com/questions/14469767/determining-which-assets-are-not-being-used-in-rails