Consider a scenario where you have the following JavaScript code running in a Firefox plugin, aimed to execute an XmlHttpRequest
on a page load:
function my_fun(){
var xmlHttpConnection = new XMLHttpRequest();
xmlHttpConnection.open('GET', globalUrl+'/call_this.php', true);
xmlHttpConnection.onreadystatechange=function(){
if (xmlHttpConnection.readyState == 4 && xmlHttpConnection.status == 200) {
var serverResponse = xmlHttpConnection.responseText;
do_stuff();
clearTimeout(xmlHttpTimeout);
xmlHttpConnection.abort();
}
};
xmlHttpConnection.send(null);
xmlHttpTimeout = setTimeout(function (){
do_other_stuff();
xmlHttpConnection.abort();
clearTimeout(xmlHttpTimeout);
},5000);
}
container.addEventListener("load", my_fun, true);
Upon invoking my_fun()
, the access logs on the Apache server display entries like this:
<client-ip> - - [06/Nov/2014:10:40:04 -0500] "GET /call_this.php HTTP/1.1" 200 1 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0"
If there are 4 client connections on the server, it's possible that within one second, this log line appears multiple times simultaneously, even originating from just one client. While there may be fewer than 5 pings per second most of the time, intermittent spikes attributable to call_this.php
could escalate the frequency.
What could be causing this behavior? One potential culprit might be the
container.addEventListener("load", my_fun, true);
. Could this be inaccurately tracking loads, especially when hidden URLs are being loaded on the page? If so, how can this issue be rectified? (Edit: Would utilizing an observer service yield better results?)