Forum Moderators: open

Message Too Old, No Replies

Javascript is stalling my page

How can you prevent this?

         

digitalv

1:15 am on Aug 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a simple snipet of Javascript that grabs a couple of news articles from a remote server, but sometimes that server is slow and it causes my page to pause until the remote server responds.

Is there any way to make the Javascript fetch AFTER everything else has loaded? It's just a little bit of text that sits inside a fixed-width cell, so the rest of the page can still look good before the news articles are displayed, but it's real irritating having to wait for that to load before continuing to render the rest of the page.

CaseyRyan

3:02 am on Aug 19, 2005 (gmt 0)

10+ Year Member



You could put the javascript at the end of your page code so that it's one of the last things that renders. Even if the cell it's filling is earlier on in the page code, you can fill it.

-=casey=-

digitalv

3:14 am on Aug 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How do you do that? The code on my page looks like this:

<script language="Javascript" type="text/javascript" src="http://www.sample.com/sample.js"></script>

It has to be placed in the exact spot I want the results to load unless you know of a way around that.

CaseyRyan

1:06 pm on Aug 19, 2005 (gmt 0)

10+ Year Member



I have this problem with my blog. Some of the additions I put in there make calls to the service providers using the same method (javascript). I ended up moving them to the end so they loaded last, then using CSS to place the content they generated in the appropriate spot.

I don't really have a good example cause I'm no good at css.

Another Idea:
Is the javascript yours? If so you might consider rewriting it so thaat the file itself doesn't autoexecute and output the content. Instead, wrap what you need to generates the content in a function, include it at the end of your code, then a javascript call on your page to call the function, retrieve the value/content and place it in the cell.

-=casey=-

kaled

2:19 pm on Aug 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must adjust your script to write to the innerHTML property of a div/span etc. You may then place the script at the bottom of the page but have it fill an element higher up.

Kaled.

digitalv

1:00 am on Aug 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must adjust your script to write to the innerHTML property of a div/span etc. You may then place the script at the bottom of the page but have it fill an element higher up.

Kaled.

How would I do that?