如何找到js的哪个部分导致页面变慢

发布于 2024-10-09 21:00:07 字数 100 浏览 3 评论 0原文

您好,我的页面在本地服务器上花费了大约 9 秒,在远程服务器上花费了大约 20 秒,我确定问题出在 js 中,但我找不到导致速度变慢的原因,您能帮我找到解决方案或任何工具吗找出问题所在?

hi my page is taking about 9s on local server and about 20s on remote server, i am sure that the problem is in js, but i can't find what makes it slow, can you please help me find a solution or any tool to hunt the problem down?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

仙气飘飘 2024-10-16 21:00:07

现在所有现代主流浏览器都内置了 js 分析。
Firebug & Chrome 都有很好的客户端脚本分析工具,他们还有 http 流量监视器,也可以帮助您诊断问题。 IE 也有一个。

以下是 Firebug 分析器的实际应用示例
alt text

[编辑]在 Chrome 中,按 Ctrl+Shift+J 打开 JavaScript 配置文件页面。

All the modern major browsers have js profiling builtin now.
Firebug & Chrome both have good client script profiling tools, also they have http traffic monitors which may also help you diagnose the issue. IE also has one.

Here is an example of the firebug profiler in action
alt text

[EDIT]In Chrome, press Ctrl+Shift+J to open the JavaScript profile page.

萌吟 2024-10-16 21:00:07

内置或添加分析工具的替代方案(我想说的首选方式):使用计时器。
我已经编写了这个:

 function Timer(){
  var start = new Date
      ,ended = 'running ...';
  return {
      start: function(){
              start = new Date; 
              return this
      },
      stop:  function(mssg) {
              var stoppedAt = (new Date - start);
           ended = [(mssg ? mssg+': ' : '')
                           ,(stoppedAt/1000)+' sec (+/- 15ms)'].join('')
              return ended;
      }
      ,toString: function(){
                return ended;
      }
  };
}
//usage:
var timenow = new Timer().start();
// run a function
console.log(timenow.stop('this took '));

您还可以使用包装函数来计时函数的执行时间。像这样的东西:

function timedFn(fn){
  var timer = new Timer().start();
  fn();
  console.log(timer.stop('function took '));
}

Alternative to built-in or add on profiling tools (the preferred way I'd say): use a timer.
I've cooked up this one:

 function Timer(){
  var start = new Date
      ,ended = 'running ...';
  return {
      start: function(){
              start = new Date; 
              return this
      },
      stop:  function(mssg) {
              var stoppedAt = (new Date - start);
           ended = [(mssg ? mssg+': ' : '')
                           ,(stoppedAt/1000)+' sec (+/- 15ms)'].join('')
              return ended;
      }
      ,toString: function(){
                return ended;
      }
  };
}
//usage:
var timenow = new Timer().start();
// run a function
console.log(timenow.stop('this took '));

You can also use a wrapper function to time the execution time of a function. Something like:

function timedFn(fn){
  var timer = new Timer().start();
  fn();
  console.log(timer.stop('function took '));
}
万水千山粽是情ミ 2024-10-16 21:00:07

我将添加 Web Developer 1.1.8 为 Firefox 添加 < a href="http://getfirebug.com/javascript" rel="nofollow">Firebug & Chrome

有关更多详细信息,请查看此内容链接

问候

Wazzy

i will add Web developer 1.1.8 Add on for Firefox with Firebug & Chrome

For more details have a look on this link

with regards

Wazzy

给我一枪 2024-10-16 21:00:07

您可以将 YSlow 用于 Firebug。从 YSlow 页面:

YSlow 分析网页,并根据一组高性能网页规则提出提高其性能的方法。 YSlow 是一个与 Firebug Web 开发工具集成的 Firefox 插件。 YSlow 根据三个预定义规则集之一或用户定义的规则集对网页进行评分。它提供改进页面性能的建议、总结页面的组件、显示有关页面的统计信息,并提供性能分析工具,包括 Smush.it™ 和 JSLint。

You can use YSlow for Firebug. From the YSlow page:

YSlow analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. YSlow is a Firefox add-on integrated with the Firebug web development tool. YSlow grades web page based on one of three predefined ruleset or a user-defined ruleset. It offers suggestions for improving the page's performance, summarizes the page's components, displays statistics about the page, and provides tools for performance analysis, including Smush.it™ and JSLint.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文