在Rails应用程序中查找未使用的图像? [英] Finding unused images in a Rails app?

查看:150
本文介绍了在Rails应用程序中查找未使用的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉自重等工具,用于查找未在Rails应用中使用的CSS,但图像有什么作用吗?我正坐在一个拥有大量资产目录的项目中,与各种设计师合作,我正在努力减少这个项目的成本。将资产转移到我们的CDN时尤其痛苦。

I'm familiar with tools like Deadweight for finding CSS not in use in your Rails app, but does anything exist for images? I'm sitting in a project with a massive directory of assets from working with a variety of designers and I'm trying to trim the fat in this project. It's especially a pain when moving assets to our CDN.

有什么想法吗?

推荐答案

这在很大程度上取决于使用图像的代码。总是有可能计算文件名(通过连接两个值或字符串替换等),所以简单地按文件名格式化并不一定足够。

It depends greatly on the code using the images. It's always possible that a filename is computed (by concatenating two values or string substitution etc) so a simply grepping by filename isn't necessarily enough.

你可以尝试运行wget (如果你有一台linux机器,可能已安装,否则 http://users.ugent.be / ~bpuype / wget / )镜像整个站点。如果可以,请在同一台计算机或网络上执行此操作,它将抓取整个网站并抓取所有图像

You could try running wget (probably already installed if you've got a linux machine, otherwise http://users.ugent.be/~bpuype/wget/ ) to mirror your whole site. Do this on the same machine or network if you can, it'll crawl your whole site and grab all the images

# mirror mysite.com accepting only jpg, png and gif files
wget -A jpg,png,gif --mirror www.mysite.com

完成后,您将获得网站层次结构的第二份副本,其中包含通过抓取您的网站可以访问的任何页面主动链接的所有图像。然后,您可以备份源映像目录,并将其替换为wget的副本。接下来,监视您的日志文件以获取与gif / jpg / png文件相关的404。希望有所帮助。

Once you've done that, you're going to have a second copy of your site's hierarchy containing any images that are actively linked to by any page reachable by crawling your site. You can then backup your source image directory, and replace it with wget's copy. Next, monitor your log files for 404's pertaining to gif/jpg/png files. Hope that helps.

这篇关于在Rails应用程序中查找未使用的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆