简体   繁体   English

如何分析JavaScript函数执行顺序

[英]How to analyze JavaScript function execution order

I have to optimize a website that uses a lot of JavaScript. 我必须优化使用大量JavaScript的网站。 I'm not the author of that site. 我不是那个网站的作者。 I just need to understand the way it works and optimize few things related to JavaScript. 我只需要了解它的工作方式并优化与JavaScript相关的一些内容即可。 And for that I need to understand what JS code is executed specifically during page load. 为此,我需要了解在页面加载期间专门执行了哪些JS代码。

I'm looking for a way to display a JavaScript functions execution order. 我正在寻找一种显示JavaScript函数执行顺序的方法。 The site I'm dealing with uses about 40 external scripts and probably 20-40 inline JS that is stuffed here and there. 我正在处理的网站使用了大约40个外部脚本,并且可能在这里和那里填充了20-40个内联JS。 The best would be Firefox add-on. 最好的是Firefox插件。

I know I can add console.log("script name"); 我知道我可以添加console.log("script name"); into each of the JS files but with that amount of code it's ridiculously unpractical. 到每个JS文件中,但是有了这么多的代码,这简直是不切实际的。 I know that Firebug ships with the profiler, but it does not allow me to see when a function was executed. 我知道Firebug随探查器一起提供,但是它不允许我查看何时执行函数。 Besides it crashes on the site I'm trying to analyze. 除此之外,它在我尝试分析的网站上崩溃了。

I just want to know the order of function execution. 我只想知道函数执行的顺序。 The site heavily relays on jQuery. 该网站主要依靠jQuery。 Almost all of these scripts are jQuery. 这些脚本几乎都是jQuery。

As in my earlier comment, try using Chrome. 就像我之前的评论一样,尝试使用Chrome。 Some useful links here to help you use the developer tools to profile JS:- 一些有用的链接可以帮助您使用开发人员工具来分析JS:-

https://developers.google.com/chrome-developer-tools/docs/cpu-profiling http://coding.smashingmagazine.com/2012/06/12/javascript-profiling-chrome-developer-tools/ https://developers.google.com/chrome-developer-tools/docs/timeline https://developers.google.com/chrome-developer-tools/docs/cpu-profiling http://coding.smashingmagazine.com/2012/06/12/javascript-profiling-chrome-developer-tools/ https:/ /developers.google.com/chrome-developer-tools/docs/timeline

Great post by Addy Osmani on timeline profiles:- 艾迪·奥斯曼尼(Addy Osmani)在时间轴配置文件上的精彩帖子:-

https://developers.google.com/chrome-developer-tools/docs/timeline https://developers.google.com/chrome-developer-tools/docs/timeline

Hope these are of use to you. 希望这些对您有用。

Mat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM