哪些javascript文件未在页面加载时使用 [英] which javascript files are NOT being used on page load

查看:93
本文介绍了哪些javascript文件未在页面加载时使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能找出哪些javascript文件未在网页上使用而无需添加控制台日志或调试或删除它们以查看是否有问题?

Is it possible to find out which javascript files are NOT used on a web page without having to add console logs or debug or removing them to see if things break?

我正在寻找一个工具,或命令行脚本或firefox插件等。

I'm looking for a tool, or a command line script or firefox plugin etc.

例如,假设我将这些包含在标题中:

For example, let's say I have these included in the header:

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/functions.js"></script>
<script type="text/javascript" src="js/validation.js"></script>
<script type="text/javascript" src="js/something.js"></script>

在页面上,只调用 functions.js中的函数 validation.js jquery.js 。我如何知道 something.js 未被使用,因此可以安全地从标题中删除?

On the page, calls are only made to functions in functions.js, validation.js and jquery.js. How can I know that something.js is not used and therefore can be safely removed from the header?

I我已经尝试过像FireBug,chrome的控制台,yslow和服务器日志这样的东西,但是这些都告诉我哪些脚本已经加载,即所有脚本,而不是哪些脚本已被使用。

I've tried rooting through things like FireBug, chrome's console, yslow and server logs, but these all tell me which scripts have been loaded, i.e. all of them, not which ones have been used.

推荐答案

AFAIK没有简单的这个文件正在使用/未使用的检测机制,因为有很多方法可以在JavaScript中调用,扩展和引用。

AFAIK there is no simple "this file is in use / not in use" detection mechanism, because there are so many ways to call, extend and reference things in JavaScript.

有很多方法可以调用函数,例如在元素的单击事件中, eval()语句...您可以扩展现有的原型脚本文件中的类...等等。此外,您可以通过AJAX获取新标记,而不是依次从某个包含引用函数,无法在不获取内容的情况下自动测试。

There are dozens of ways to call a function, e.g. in the click event of an element, eval() statements... You could be extending the prototype of an existing class in a script file... etc. Also, you could be fetching new markup through AJAX than in turn references functions from a certain include, something impossible to test for automatically without fetching the content.

除非有人提出一个解决这个问题的工具(我不是说这是不可能的,只是它非常难)我会说用一个好的IDE和搜索功能手动完成这个工作就是最佳方式。

Unless somebody comes up with a tool that tackles exactly this (I'm not saying it's impossible, just that it is horribly hard) I'd say working this out manually with a good IDE and search function is the best way to go about it.

这篇关于哪些javascript文件未在页面加载时使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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