Recently, I developed a script using jQuery for AJAX that allows me to "ping" the server and measure the time it takes for my AJAX requests to complete.
var start = Date.now(), end = 0;
setInterval(function() {
$.ajax('', {
complete: function() {
end = Date.now();
console.log(end - start);
}
});
}, 1000);
After implementing this script, the output pattern I observed was:
39
2
4
2
3
40
3
2
3
4
2
61
9
4
3
2
2
4
34
I found it interesting how the duration of the "ping" jumps from lower numbers like 2 or 3 to higher ones like 40 or 50 in a repeated pattern. Is there a specific reason behind this behavior, or should I attribute it to the complexities of HTTP/AJAX technology?