...

View Full Version : Loading JS first or fast at the time opening the website



tommyswf
06-13-2008, 05:25 AM
I would like to know is there any medthod to load javascript file at the very first when the website on loading like images content etc.. could make the js load before them? or make it load faster

thanks
Tommy

Philip M
06-13-2008, 07:41 AM
If you place your external .js file right after ther <body> tag it will load first.
But of course if the .js file runs on load and references html elements which have not yet loaded then an error occurs. In other words, any JavaScript that affects the way a page displays – either its content or its styling – has to first make sure that everything it requires is there i.e. that the page it's working on is downloaded (and parsed).

In fact many people recommend placing your JavaScript at the end of your HTML file if possible, right before the closing </body> tag. This allows the majority of page content (like images, tables, text) to be loaded and rendered first. The user sees content loading, so the page looks responsive. At this point, the heavy javascripts can begin loading near the end.

Only core files that are absolutely needed in the beginning of the page load should be in the <head> section. The rest, like cool menu effects, transitions, etc. can be loaded later. You want the page to appear responsive (i.e., something is loading) up front.

In any case you need to consider what happens if the user does not have JavaScript enabled.

barkermn01
06-13-2008, 12:15 PM
or better still
there is an onload function in HTML for Javascript
so use
<script type="text/javascript">
your javascript
</script>
<body onload=" your javascript ">

this loads the javascript into the page before any HTML

rnd me
06-14-2008, 07:16 AM
or better still
there is an onload function in HTML for Javascript
so use
<script type="text/javascript">
your javascript
</script>
<body onload=" your javascript ">

this loads the javascript into the page before any HTML

no is doesn't.
in fact, just the opposite is true.

onload fires only after ALL the html and scripts (and images in ff/ie/op) has finished loading.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum