Welcome to WebmasterWorld Guest from 23.20.238.193

Forum Moderators: open

Message Too Old, No Replies

Javascript search box takes time to load

     
4:37 pm on Jul 2, 2011 (gmt 0)

5+ Year Member



Can anyone advise.

I have a Javascript search box on my website that uses search results from another domain. All works very well with the search box and search results show up in a 'new window'.

The 'problem' that I have is that when I first load my website the web page loads and then a split second later the search box appears and the same thing happens if I hit the refresh button.

It all works okay but just doesn't look great when first going to my website pages.

Anything to suggest with the code tht might help or improve this or any other suggestions?

The script is long these lines:

<script src="http://greenwidgetxyz.com/search.php?showid=&fixed=1&amp;hidelabels=1" type='text/javascript'></script>

Thanks in advance
8:49 pm on Jul 5, 2011 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Is the search box part of your HTML markup, or is it generated by your script (as linked to above)? Or is it hosted on another domain entirely and displayed with an IFRAME?

Where is your script element? IF your search box is generated by script and you are linking to the script in the HEAD section then try moving the script element to before the closing </body> tag. Although, depending how the script is written, this might not make any difference. Bascially, if the search box is created by script and the script is waiting for your entire page to load before generating it then you are going to see a delay. ...but it could depend on other factors regarding your page structure.
10:11 pm on Jul 5, 2011 (gmt 0)

5+ Year Member



Hi Penders,

I have added the script within my html and it is a .php script which runs from another domain.... the search box displays on my website but with a 'split-second' delay in loading from the rest of my web pages.

Gemini23
2:50 pm on Jul 12, 2011 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Hi Gemini23, having had a look at your page it would seem the external PHP script simply returns a large
document.write(...)
(chunk of JavaScript) that is then written in-place into the page.

I wouldn't have said this is a cross-domain issue (in fact it might even help that it's on another domain), but I suspect the delay you are seeing is simply the time it takes to make another request to the server (your own or external), for the PHP code to run and then return the response (the JavaScript).

If you are running PHP on your server then you could possibly make this request direct from your server to the external server and return the JavaScript with the rest of the page. However, this is likely to slow down your initial page load I would have thought.

Without too much of a code rewrite I would have thought that the best/easiest solution would be to not concentrate too much on actually speeding it up, but just make it look quicker by including some kind of placeholder where the search box should go and switching this with the real search box once it has loaded - minimising the 'page flicker'. The placeholder could even be a static image of the real search box? Or simply a "Loading..." message?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month