为什么花费的时间为AJAX请求跳从2毫秒到50毫秒和更高? [英] Why does the time taken for AJAX request jump from 2ms to 50ms and higher?
本文介绍了为什么花费的时间为AJAX请求跳从2毫秒到50毫秒和更高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个小脚本(使用jQuery的AJAX)为平的服务器并输出需要多长时间才会发生我的AJAX请求。
I wrote a small script (with jQuery for AJAX) to "ping" the server and output how long it takes for my AJAX requests to occur.
var start = Date.now(), end = 0;
setInterval(function() {
$.ajax('', {
complete: function() {
end = Date.now();
console.log(end - start);
}
});
}, 1000);
这是我发现了一种模式:
This is the kind of pattern I'm getting:
39
2
4
2
3
40
3
2
3
4
2
61
9
4
3
2
2
4
34
等。
为什么从一个低数(2,3,4,等)的ping跳转到一个较高的一个(40,50,60)以这样的图案?是否有一个明显的原因,或者我应该只是责怪HTTP / AJAX技术?
Why does the "ping" jump from a low number (2, 3, 4, etc.) to a higher one (40, 50, 60) in such a pattern? Is there an obvious reason or should I just blame it on HTTP/AJAX technology?
推荐答案
与40ms左右在你的榜样这些请求是真实的请求。其他人则通过缓存器的结果。
Those requests with about 40ms in your example are real requests. Others are cached results by browser.
这篇关于为什么花费的时间为AJAX请求跳从2毫秒到50毫秒和更高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文