Click to See Complete Forum and Search --> : External Script takes forever to load


BrainDonor
01-06-2004, 06:19 PM
Hello...

I have a form that used like a search engine, howver, when I generate the external js file, it takes a long time to load. What I'm wondering is if there is a way this can be optimized?

Here is the code for the form:
<HTML>
<HEAD>
<script language="JavaScript" src="client_search.js"></script>

<TITLE>Client Inquiry</TITLE>
</HEAD>
<BODY onContextMenu="return false;" topmargin='8'>

<FORM NAME="F187" onSubmit="MySearchF(); return false">

<br>Enter a search word or phrase:<br>
<INPUT TYPE="TEXT" NAME="MyText" VALUE="" SIZE="35" MAXLENGTH="50">
<INPUT TYPE="BUTTON" VALUE="Search" onClick="MySearchF();"><BR>

<SELECT NAME="MySelect" style="width:550" size="20" onDblClick="searchGo();">
<OPTION>Search results will be displayed here
</SELECT>
<BR>
<INPUT TYPE="BUTTON" VALUE="Go!" onClick="searchGo();">
<br>
</FORM>

</body>
</html>

Here is the code for the referenced js file: (I shortened it severely so as not to clog up the forums. The numbers [0], [1] in the first part will go all the way to 25K easily.)

function MySearchF()
{
nullOptions(document.F187.MySelect);

URLs=new Array()
titls=new Array()
Kwds=new Array()

URLs[0]="050000.html";
titls[0]="050000 - COMPANY 1";
Kwds[0]="050000,COMPANY, INCORPORATED";

URLs[1]="050001.html";
titls[1]="050001 - UNICORP";
Kwds[1]="050001,UNICORP,TEXTILE";

var joined=new Array()
{
for (i=0;i<URLs.length; i++)
{
joined[i]=titls[i]+Kwds[i]
}
Searchphrase=document.F187.MyText.value
j=0;
checker=0;
if (document.F187.MyText.value.length<1)
{
alert('Please enter something to search for.');
}
else
{
var myFoundURL=new Array();
var myFoundText=new Array();
for (i=0;i<URLs.length; i++)
{
if (joined[i].indexOf(Searchphrase.toUpperCase())>-1)
{
checker+=1;
j++;
myFoundURL[j]=URLs[i];
myFoundText[j]=titls[i];
}
}
if (checker>0)
{
document.F187.MySelect.options[0]=new Option('Results: '+checker,'')
for (j=1;j<checker+1;j++)
{
document.F187.MySelect.options[j]=
new Option(myFoundText[j],myFoundURL[j]);
}
}
else
{
document.F187.MySelect.options[0]=new Option('Sorry! Could not find anything to match that string:','')
}
}
}
}
function nullOptions(aMenu)
{
tot=aMenu.options.length;
if (aMenu.options.length>0)
for (i=0;i<tot;i++)
{
aMenu.options[i]=null
}
aMenu.options.length=0;
}
function searchGo()
{
var w = screen.width - 12;
var h = screen.height - 66;
if (document.F187.MySelect.selectedIndex>0)
{
var newwin=document.F187.MySelect.options[document.F187.MySelect.selectedIndex].value;
window.open(newwin,'ViewData','width=' + w + ',height=' + h + ',history=no,resizable=yes,status=no,scrollbars=yes,menubar=no,left=0,top=0');
}
else
{
alert('Please select an option.')
}
}

This works just great, but as I said, takes way too long to load when I have the full file generated. Any help you can offer would be greatly appreciated!!

Tom

olerag
01-06-2004, 06:46 PM
What is the time difference if you placed all of the code in
an htm file instead of loading it as a script? If alot, I guess
it is a "load" problem, otherwise (if the time is the same)
the problem (if any) is with the code.

BrainDonor
01-06-2004, 06:57 PM
I appreciate your reply. I had the code in the html page at first and thought it would load faster with moving it to an external script. Much to my dismay, there was no difference. Basically, what I'm trying to do is create a search engine type of program that will cycle through pre-generated reports and output the results to the text area on the form. Do I have any other options?

olerag
01-06-2004, 07:42 PM
...create a search engine type of program that will
cycle through pre-generated reports and output the results...


Lets put it this way. Search engines (whether to "spider"
sites or produce fast database or file i/o results) are intricately
prepared and can cost, well, lots.

If your search tool works but is taking a long time to display
the results correctly, you have a decision to make. But I
don't think the answer is JS.

BrainDonor
01-06-2004, 07:52 PM
I think you're misunderstanding what I am trying to do...rather, I think I didn't explain it well enough. This is for an Intranet where I work. The js file is that part that takes too long to load. The results display quite quickly. What I'm wondering is if there's a way I can make the page load faster. The results are then posted into the textarea with a row count of the results. It works very well, but is just slow to load initially. The pre-compiled reports I spoke of are just simply HTML files that store information about our clients. I've written an Informix-4gl program to output the reports in HTML format and am now looking to expand on that by making the reports searchable.

olerag
01-06-2004, 08:24 PM
OK, sorry (oh, and congrats on the OT win)...

If your satisfied with the performance of the search and
your only concern is the ~25K of JS code loaded, all I can
recommend is to analyze and, possibly, consolidate the
code. I know of no way to have JS hasten the speed in
which it loads its code besides obtaining faster hardware.

Maybe someone else can help though.

BrainDonor
01-06-2004, 08:30 PM
Thanks olerag. I am very happy with the speed of the search. I appreciate your replies. Is there a way to have JavaScript read through a text file and only output the hits? Kind of like the grep command in Unix? Just a thought...and since I know very little about JS, I had to ask.

On a separate note, I am quite certain the Packers will handle Philly...maybe even a bit easier than the Seahawks. The Packers have been riding on a wave of emotion the last few weeks and I, for one, believe this wave will take them to at least the NFC Championship game. Just my humble opinion.

olerag
01-06-2004, 08:37 PM
You won't be doing any file i/o using JS. You'll need your
server-side language to perform you file examinations and
then, possible, produce the results back into HTML.

Don't know about ur 2nd para - good game though. Lucky
that they won't be facing Colts though. Don't think I've
even seen a QB have a game like Manning had.

BrainDonor
01-06-2004, 08:45 PM
Well, from what I've been finding on the web...it appears that my JS route just won't work. Because this is basically client-side, the whole "search engine" has to be downloaded to the users PC so they can do the search. That just won't work. Our Unix server does have Apache and I am pretty sure that I can use a server-side script for this (need to find out what our server supports), but I am not familiar enough with it to make a go at it...not yet anyway.

You're right...Manning is an excellent QB...but, who knows...if things fall the right way we may end up meeting them at the big dance. Stranger things have happened.

BrainDonor
01-07-2004, 09:04 AM
Is my approach here the easiest as far as coding goes? Is there anything I can do to "tone down" the amount of text in the arrays for the searching? Just thought I'd ask.

Thanks!

Tom

BrainDonor
01-07-2004, 10:05 AM
Is it possible to fire a Unix shell script from JavaScript?

olerag
01-07-2004, 10:44 AM
Using an anchor, JS can find the file on the local drive but
I believe all it will try to do is read the info into the
browser. It won't actually execute anything.

Here again I'm not sure but I don't believe JS is your
solution for your file i/o requirements.