JavaScript Speed issues
Posted: Fri May 09, 2008 3:52 pm
I am building a very simple vxml app that uses the <data> tag to go out and call a web service and speak back the account info . The web service does not return a fully structured XML but rather a single string with a pound sign (#) to delimit the different accounts and a comma to delimit the fields in the account. I use the <script> tag to execute some JavaScript that basically pulls apart the single string using the delimiters and assign them to vxml vars. The problem I am having is that while the JS is doing everything right, it can take up to 15 seconds to parse through the string, sometimes even longer and confused the caller thinking something is wrong! When I execute the code using a browser, it comes back super quick and I even tried the code with another IVR platform and it too comes back real quick and with much less GHz speed on the hardware side.
What could be going wrong here? Should I avoid JS?
I'll do my best to describe the code here without listing the entire app.
This is what a return string looks like from the web service:
<string>0,999999991,,,0,0,0#1,000023336,,,0,1300,1300#2,000005365,,06/01/2008,0,241.61,129.38#3,05K678321,,06/01/2008,0,250.37,167.28#4,392840464,,,0,0,4632.5#5,000000000,,,0,0,-263.59</string>
<!-- Globals -->
<var name="gc_accounts_string" expr=""/>
<var name="each_account" expr=""/>
<!-- Get Account String Web Service -->
...
<data name="domXMlData" src="http://mywebserver.com/ivr.asmx/GetAccountsString" namelist="sToken sSSN Sep1 Sep2" method="post" />
<block>
<assign name="gc_accounts_string" expr="domXMlData.documentElement.firstChild.toString()"/>
</block>
### The JS call below, separates out the account by using the # delimiter
<block cond="segment_account_info()">
....
</block>
<block cond="account_index < gc_account_count" name="play_accounts">
### The JS call below, separates out the fields in the account by using the , delimiter. In this case, I use an index counter in a loop to load the field values in vars to play back
<if cond="get_account_info(account_index)">
### In between I play back the values returned in the JS below.
</if>
</block>
### I use the JS SPLIT method to separate out the accounts and fields in the accounts.
<script>
function segment_account_info() {
var the_accounts = gc_accounts_string;
each_account = the_accounts.split("#");
return true;
}
function get_account_info(i) {
var elements = each_account.split(",");
record = elements[0];
loanid = elements[1].substr(6,3);
lastpaymentdate = elements[2];
nextpaymentdate = elements[3];
lastpayment = elements[4];
nextpayment = elements[5].split(".");
dollarsdue = nextpayment[0];
centsdue = nextpayment[1];
balance = elements[6].split(".");
dollarsbalance = balance[0];
centsbalance = balance[1];
return true;
}
</script>
What could be going wrong here? Should I avoid JS?
I'll do my best to describe the code here without listing the entire app.
This is what a return string looks like from the web service:
<string>0,999999991,,,0,0,0#1,000023336,,,0,1300,1300#2,000005365,,06/01/2008,0,241.61,129.38#3,05K678321,,06/01/2008,0,250.37,167.28#4,392840464,,,0,0,4632.5#5,000000000,,,0,0,-263.59</string>
<!-- Globals -->
<var name="gc_accounts_string" expr=""/>
<var name="each_account" expr=""/>
<!-- Get Account String Web Service -->
...
<data name="domXMlData" src="http://mywebserver.com/ivr.asmx/GetAccountsString" namelist="sToken sSSN Sep1 Sep2" method="post" />
<block>
<assign name="gc_accounts_string" expr="domXMlData.documentElement.firstChild.toString()"/>
</block>
### The JS call below, separates out the account by using the # delimiter
<block cond="segment_account_info()">
....
</block>
<block cond="account_index < gc_account_count" name="play_accounts">
### The JS call below, separates out the fields in the account by using the , delimiter. In this case, I use an index counter in a loop to load the field values in vars to play back
<if cond="get_account_info(account_index)">
### In between I play back the values returned in the JS below.
</if>
</block>
### I use the JS SPLIT method to separate out the accounts and fields in the accounts.
<script>
function segment_account_info() {
var the_accounts = gc_accounts_string;
each_account = the_accounts.split("#");
return true;
}
function get_account_info(i) {
var elements = each_account.split(",");
record = elements[0];
loanid = elements[1].substr(6,3);
lastpaymentdate = elements[2];
nextpaymentdate = elements[3];
lastpayment = elements[4];
nextpayment = elements[5].split(".");
dollarsdue = nextpayment[0];
centsdue = nextpayment[1];
balance = elements[6].split(".");
dollarsbalance = balance[0];
centsbalance = balance[1];
return true;
}
</script>