如何在Web项目中查找未使用/死代码(javascript中的90%代码) [英] How to find unused/dead code in web projects (90% code in javascript)

查看:267
本文介绍了如何在Web项目中查找未使用/死代码(javascript中的90%代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一个非常有趣的工具,用于识别Web项目中未使用的CSS定义。
http://www.sitepoint.com/dustmeselectors/

I did find a very interesting tool for identify unused css definitions in a web project. http://www.sitepoint.com/dustmeselectors/

javascript项目是否也有类似的工具?

Are there similar tools also for javascript projects?

PS
我知道没有确定性地找到未使用代码的程序。但我正在寻找一份报告来确定可能未使用的代码。然后最后的决定将永远是你自己的。

P.S. I know there is no program for deterministically finding unused code. But I am looking for a report to identify possible unused code. Then the last decision will always be your own.

推荐答案

问题是没有办法确定。假设如下:

Problem is there is no way to be really sure. Suppose the following:


  1. 最初的HTML网站几乎是空的。虽然有很多JS代码,但它们似乎未被使用。

  2. OnLoad,调用一个函数向服务器发起一个AJAX查询。服务器返回大量HTML代码,这是站点的主体。这个主体包含许多JavaScript函数。

  3. 初始正文被替换为通过AJAX接收的正文。突然间,使用了所有代码。

静态分析实用程序因此无用。我不知道是否存在一个浏览器扩展,它标记了正在运行的浏览器中的所有JS使用情况。

Static analysis utilities are therefore useless. I do not know whether there exists a browser extension that marks all JS usage from a running browser though.

这篇关于如何在Web项目中查找未使用/死代码(javascript中的90%代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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