如何追踪HTTP请求?
尝试优化一个网络项目。
它使用 asp.net (webforms)、一堆 jquery 插件等等。
问题:对 localhost/undefined
存在不必要的 HTTP 请求,这使得每个请求花费的时间比需要的时间长约 1 秒。
问:有什么策略可以找到有罪的代码吗?
线索: undefined
让我觉得涉及到了 JS。
萤火虫日志:
GET /未定义 HTTP/1.1
主机:本地主机:17817
用户代理:Mozilla/5.0(Windows;U;Windows NT 6.1;lv;rv:1.9.2)Gecko/20100115
火狐/3.6
接受:image/png,image/;q=0.8,/;q=0.5
接受语言:lv,en-us;q=0.7,en;q=0.3
接受编码:gzip、deflate
接受字符集:ISO-8859-13,utf-8;q=0.7,;q=0.7
保持活动:115
连接:保持活动
引用者: http://localhost:17817/Default.aspx
如果右键单击代码中的一行,它会给您一个条件断点。检查有URL值的变量名称,当typeof URL === 'undefined'或url === 'undefined'时设置一个条件并查看堆栈
在第 3400 行设置断点(无条件)。它不会经过那里。
3397 ajax: 函数( s ) {
第3398章 第3399章 第3400章
问题缩小了一点=>注释掉 1 个 ascx 控制器,该控制器渲染一些图像并使用 galleryrific jquery 插件和 magic request 消失。
问题出在画廊插件初始化上。它找不到锚点,它是在没有图像或其他东西时创建缩略图的 href。现在很酷...
Trying to optimize one web project.
It uses asp.net (webforms), bunch of jquery plugins and whatnot.
Problem: there's unnecessary HTTP request to localhost/undefined
and that makes every request take ~1s longer than needed.
Question: is there any tactic to find guilty code?
Clue: undefined
makes me think that there's JS involved.
Firebug log:
GET /undefined HTTP/1.1
Host: localhost:17817
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; lv; rv:1.9.2) Gecko/20100115
Firefox/3.6
Accept: image/png,image/;q=0.8,/;q=0.5
Accept-Language: lv,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-13,utf-8;q=0.7,;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://localhost:17817/Default.aspx
if you right click a line in the code, it gives you a conditional breakpoint. Check the name of the variable that has the URL value, and set a condition when typeof URL === 'undefined' or url === 'undefined' and look at the stack
Just set breakproint at line 3400 (with no conditions). It does not go through there.
3397 ajax: function( s ) {
3398 // Extend the settings, but re-extend 's' so that it can be
3399 // checked again later (in the test suite, specifically)
3400 s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
Narrowed issue down a bit => commented out 1 ascx controller that renders some images and uses gallerific jquery plugin and magic request dissapeared.
Problem was with galleriffic plugin initialization. It couldn't find anchor and it's href for creating thumbnails when there were no images or something. It's cool now...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否能够识别出哪些 JS 代码正在发起请求?如果您使用 Firebug,它应该在控制台窗口中为您提供一行调用 AJAX 请求的代码。如果它类似于 jQuery 库中带有代码行的 $.post(),您可以在 Firebug 插件中导航调用堆栈,尝试找出调用初始 JS 调用的位置。
Have you been able to identify what JS code is initiating the request? If you are using Firebug it should give you a line of code in the console window which is invoking the AJAX request. In the event it's something like a $.post() with a code line in the jQuery library, you can navigate the callstack within the Firebug plugin to try and figure out where the initial JS call is being invoked.
您可能想尝试HTTP Watch。
You might want to try out the HTTP Watch.