检测链接&未使用的文件和未使用的JavaScript [英] Detect linked & unused files and unused JavaScript

查看:87
本文介绍了检测链接&未使用的文件和未使用的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了我的网站,这是我2年前开始的。我一直在尝试新的东西,有时包括添加不同的框架或其他外部JS文件。

I just finished my website, which I started 2 years ago. I was always trying new things, which sometimes included adding different frameworks or other external JS files.

现在我不知道JS的哪些链接文件/行是没用过。有没有可以检测这些文件和代码行的工具?这会节省我很多时间。

Now I don't know which of the linked files/lines of JS are unused. Is there a tool which can detect these files and lines of code? It would save me a lot of time.

推荐答案

答案提供了 Google的Closure Compiler ,其中包含缩小和连接JavaScript代码,可以删除死代码。

This answer offers Google's Closure Compiler which, in the process of minifying and concatenating your JavaScript code, can remove "dead code".

引自编译级别的文档


使用ADVANCED_OPTIMIZATIONS进行编译会删除代码可证明是无法到达的。这与大型库结合使用时尤其有用。如果您只使用大型库文件中的一些函数,编译器可以从其输出中删除除这些函数之外的所有函数。

Compilation with ADVANCED_OPTIMIZATIONS removes code that is provably unreachable. This is especially useful in combination with large libraries. If you use only a few functions from a large library file, the compiler can remove everything except those functions from its output.

另请参阅此答案包含有关Google Closure Compiler的更多信息。

Also see this answer which contains more information on Google's Closure Compiler.

这篇关于检测链接&未使用的文件和未使用的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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