Determining which assets are not being used in Rails?

白昼怎懂夜的黑 提交于 2019-12-07 11:56:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!