Javascript 查找未使用的图像、css 规则、js 脚本块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2224154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
find unused images, css rules, js script blocks
提问by Pratik Kothari
We have a fairly large asp.net website.
我们有一个相当大的asp.net 网站。
The images, css and javascripts are property organized in the website project but as we are changing the look and feel of the website, I would like to know if there is a tool/add-in that will help me identify which images are not being used in the website.
图像、css 和 javascripts 是在网站项目中组织的属性,但随着我们正在改变网站的外观和感觉,我想知道是否有一个工具/插件可以帮助我识别哪些图像不是网站中使用。
I would like to find the same thing with css and javascript as well. I have looked at dustme firefox extension but that only does css.
我也想用 css 和 javascript 找到同样的东西。我看过dustme firefox 扩展,但那只做css。
回答by Somnath Muluk
Unused CSS
未使用的 CSS
Take a look at the Firefox extension Dust-Me at http://www.sitepoint.com/dustmeselectors/.
Google Chrome has a website auditing toolin their developer console.
Also I found this site for removing unused css - http://unused-css.com/. Type the url of a site and you will get a list of CSS selectors. For each selector, a number indicates how many times a selector is used. This service has a few limitations. The @import statement is not supported. You can't configure and download the new clean CSS file.
HeliumCSS is a javascript tool for discovering unused CSS across many pages on a web site. You first have to install the javascript file to the page you want to test. Then, you have to call a helium function to start the cleaning.
CSSESSis a bookmarklet that helps you find unused CSS selectors on any site. This tool is pretty easy to use but it won't let you configure and download clean CSS files. It will only list unused CSS files.
在http://www.sitepoint.com/dustmeselectors/ 上查看 Firefox 扩展 Dust-Me 。
谷歌浏览器在其开发者控制台中有一个网站审核工具。
我还发现这个站点用于删除未使用的 css - http://unused-css.com/。输入站点的 url,您将获得 CSS 选择器列表。对于每个选择器,一个数字表示一个选择器被使用的次数。此服务有一些限制。不支持 @import 语句。您无法配置和下载新的干净 CSS 文件。
HeliumCSS 是一个 javascript 工具,用于在网站的许多页面中发现未使用的 CSS。您首先必须将 javascript 文件安装到要测试的页面。然后,您必须调用氦功能来开始清洁。
CSSESS是一个书签,可帮助您在任何站点上找到未使用的 CSS 选择器。这个工具很容易使用,但它不会让你配置和下载干净的 CSS 文件。它只会列出未使用的 CSS 文件。
Unused Images:
未使用的图像:
- http://obsidience.blogspot.in/2008/06/using-powershell-to-find-unused-images.html
- How Do I Make a Bash Script To Find Unused Images in a Project?
- http://obsidience.blogspot.in/2008/06/using-powershell-to-find-unused-images.html
- 如何制作 Bash 脚本来查找项目中未使用的图像?
Unused JS:
未使用的 JS:
回答by H. Green
One possible approach would be:
一种可能的方法是:
- to use your browsers save-for-offline functionality and do an entire download of the site and all its resources to a local folder.
- Then run a little perl script that will slurp up all the *.{jpg,png,gif...etc}
- then do a diff on the list when you run it from your project source directory.
- 使用浏览器的离线保存功能,并将站点及其所有资源完整下载到本地文件夹。
- 然后运行一个小的 perl 脚本,它将把所有的 *.{jpg,png,gif...etc}
- 然后在从项目源目录运行它时对列表进行比较。
Obviously there are some limitations to this approach but if its all you have it might be a good start!
显然,这种方法有一些限制,但如果你拥有它,它可能是一个好的开始!
回答by Mohib Sheth
Since Javascript is a dynamic language and called in dynamic ways, you wont fine a tool to find unused javascript.
由于 Javascript 是一种动态语言并以动态方式调用,因此您无法使用工具来查找未使用的 javascript。
You can use a tool call JSCoveragewhich profiles your code and lists which methods are called. This should help you a bit.
您可以使用调用JSCoverage的工具来分析您的代码并列出调用的方法。这应该对你有所帮助。
回答by o.v.
I never had luck with any browser extensions that claim to do just that.
我从来没有遇到任何声称可以做到这一点的浏览器扩展。
I run a console app that relies on AgentRansackto find unused css classes in the project directory (i.e. declared but not referenced in ascx/js etc.) - then it merges the results into a usage report. I'm assuming this could be fairlyeasily adjusted to look for image srcs etc., as long as the project directory has unused pages removed.
我运行一个控制台应用程序,它依赖于AgentRansack在项目目录中查找未使用的 css 类(即在 ascx/js 等中声明但未引用) - 然后将结果合并到使用报告中。我猜想这可能是很容易调整,以寻找图像索马里红新月会等,只要是项目目录具有去除未使用的页面。
Is there demand for a properly distributed tool like that?
是否需要像这样适当分布的工具?
回答by Leonid
Server will not open unused files, so you can check last access time. Right?
服务器不会打开未使用的文件,因此您可以查看上次访问时间。对?

