Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to load a JS file after page is done loading.

Status
Not open for further replies.

vlus

Technical User
Sep 26, 2002
45
0
0
Looking at:

The script the runs the filmstrip scroller on the right, holds up the rest of the page from loading until the script and associate thumbnails have loaded.

I call the script from its position in the main body with:
Code:
<SCRIPT LANGUAGE="Javascript" SRC="js/Pic_Scroll_Group.js"></SCRIPT>



What would like to do, is ... not have that script or its thumbnails start to load until the whole page has finished loading.

I thought maybe with an iframe, thinking the iframe wouldnt load until the rest of the page... but it starts to load at the same time as rest of page.

Then i was thinking somehow use onLoad from within the BODY tag, but:

a) i dont understand how to get it to load the whole script not just a function, and
b) i cant figure out how to get it to put the script where i want it within the page.

Then i was thinking maybe use onLoad in combo with the iframe, but didnt know if that would work either, thinking that maybe the onLoad would just figure when the iframe was done loading and prematurely start the js, when the rest of the page wasnt done yet.

Finally, I thought maybe write a tiny js that would check to see if the entire page has loaded, if yes, then load the scroller script in its place. The problem with that, is I do not have the knowledge to write a script from scratch.

So any waysss... i've spent the entire weekend and burnt myself out on this one... any thoughts? If it will help, I can post the JS file on the web, if seeing it would help.

Thanks in advance for any assistance!
Vick



Affordable Web Hosting - Just Pennies a Day at:
Web-Hostess.com[/LINK]
 
vlus,

Do instead this?
[tt]
<SCRIPT LANGUAGE="Javascript" SRC="js/Pic_Scroll_Group.js" [blue]defer[/blue]></SCRIPT>
[/tt]
- tsuji
 
vlus, I hope some other members can step in. I'm calling the day within minutes. In the meantime, ...
- tsuji
 
To prevent confusion, in my last comment above, the word 'now' should be "NOT".... the script is NOT executing where it is positioned on the page, it is opening on a fresh page replacing the original content.

Compare:

with


which are variations of the defer attribute.

Thx
Vick

Affordable Web Hosting - Just Pennies a Day - Full Control Panel - FREE Trial!
Visit Web-Hostess.com![/LINK]
 
I've duplicated the problem on another website with a simpler JS, and it does the same thing.

Compare:
with

By simply adding the defer attribute it breaks the page... anyone have any insight on this?

Thx in advance for light shed!
Vick

Affordable Web Hosting - Just Pennies a Day - Full Control Panel - FREE Trial!
Visit Web-Hostess.com![/LINK]
 
vlus,

If the scr js produces display on the current page and affect the layout and shape of it, it would be inappropriate to use the defer attribute.

In case it does, you raise an interesting issue by saying it execute in the context other than the current page. This I am taking note and willing to experiment further.

- tsuji
 
vlus,

How about try doing this construction in the header script see how it behaves?
Code:
<script type="text/javascript">
function getRemote () {
	var oelem=document.createElement("script");
	oelem.src="js/Pic_Scroll_Group.js";
	oelem.type="text/javascript";
	oelem.defer=true;
	document.getElementsByTagName("head")[0].appendChild(oelem);
}
window.onload=getRemote;
</script>
- tsuji
 
tsuji:

Hello again. I placed the script, as directed, see:

I think it is trying to do something, but I dont think it actually worked. To test this, I scrolled to bottom of page, and reloaded page several times.

In most cases, it seemed clear that the scroller script was loading itself and related images simultaneously with the rest of page. Maybe because the script is still being referred from within the body.

So, I did 2 more tests meet-the-band6a and 7 which I removed the reference to the script from within the body, and then tried just placing your script in its place within the body. Neither of those produced good result.

Is there a tiny script that can be placed within the body of html, at the place where this scroller needs to be, such a script would look to see if the document has finished loading and if so, then it would call the scroller script? Which if its placed in the right spot, then the scroller should land in the right spot?

Vlus


Affordable Web Hosting - Just Pennies a Day - Full Control Panel - FREE Trial!
Visit Web-Hostess.com![/LINK]
 
vlus,

I think the vertical scroller does have a bearing on the layout of the page, hence, a defer attribute would be inappropriate for it.

Having said that. It remains to explain what you said seen. It could be that it actually does what it supposed to do---namely, it execute itself last. Now, within it, there is a document.write (txt) after the script sniff client browser type. It writes to the page, together with other thing if there are. The result is what you'd thought more dramatically executed in its "external" context---that, I don't think so.

The thing I _would_ do to experimenting in improving performance at load up is:
[1] Move the sniffing part away from the src script and place it into your page directly.
[2] Move out the window.onload as well. (window.onresize? maybe, have to assess.)
[3] The remaining function remain in the scr script with defer.
Maybe you evaluate the necessity and try some of the idea here?

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top