N
NickPick
I'm currently working on a site that will generate a lot of traffic
for the server. It refreshes certain text items every second with a
XMLHttpRequest Object (as seen below). The javascript getData function
is called every second (it is called every second for every object).
My question is, how can I optimize the performance. It happens from
time to time that the object are not ready yet before they are called
again (i.e. no "200" reply), which results in no refresh. Is this
performance problem likely on the server side or could it be a client
problem as well? Would it be more efficient to use only one object
that refreshes a lot of data rather than many objects that refresh
little data only?
Any advice is appreciated
<script type="text/javascript">
var XMLHttpRequestObject = new Array();
for (var x=0;x<=20;x=x+1) {
XMLHttpRequestObject[x] = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject[x] = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject[x] = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function getData(dataSource, divID, objNo)
{
if(XMLHttpRequestObject[objNo]) {
var obj = document.getElementById(divID);
XMLHttpRequestObject[objNo].open("GET", dataSource);
XMLHttpRequestObject[objNo].onreadystatechange = function()
{
if (XMLHttpRequestObject[objNo].readyState == 4 &&
XMLHttpRequestObject[objNo].status == 200) {
obj.innerHTML = XMLHttpRequestObject[objNo].responseText;
}
}
XMLHttpRequestObject[objNo].send(null);
}
}
</script>
for the server. It refreshes certain text items every second with a
XMLHttpRequest Object (as seen below). The javascript getData function
is called every second (it is called every second for every object).
My question is, how can I optimize the performance. It happens from
time to time that the object are not ready yet before they are called
again (i.e. no "200" reply), which results in no refresh. Is this
performance problem likely on the server side or could it be a client
problem as well? Would it be more efficient to use only one object
that refreshes a lot of data rather than many objects that refresh
little data only?
Any advice is appreciated
<script type="text/javascript">
var XMLHttpRequestObject = new Array();
for (var x=0;x<=20;x=x+1) {
XMLHttpRequestObject[x] = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject[x] = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject[x] = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function getData(dataSource, divID, objNo)
{
if(XMLHttpRequestObject[objNo]) {
var obj = document.getElementById(divID);
XMLHttpRequestObject[objNo].open("GET", dataSource);
XMLHttpRequestObject[objNo].onreadystatechange = function()
{
if (XMLHttpRequestObject[objNo].readyState == 4 &&
XMLHttpRequestObject[objNo].status == 200) {
obj.innerHTML = XMLHttpRequestObject[objNo].responseText;
}
}
XMLHttpRequestObject[objNo].send(null);
}
}
</script>