homepage Welcome to WebmasterWorld Guest from 23.23.8.131
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript search box takes time to load
Gemini23

5+ Year Member



 
Msg#: 4334174 posted 4:37 pm on Jul 2, 2011 (gmt 0)

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

 

penders

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



 
Msg#: 4334174 posted 8:49 pm on Jul 5, 2011 (gmt 0)

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.

Gemini23

5+ Year Member



 
Msg#: 4334174 posted 10:11 pm on Jul 5, 2011 (gmt 0)

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

penders

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



 
Msg#: 4334174 posted 2:50 pm on Jul 12, 2011 (gmt 0)

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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved