Click to See Complete Forum and Search --> : <script></script> tags


davidgraham16
01-01-2003, 05:27 PM
Hi
If I have several scripts in the same web page, do I need to enclose each script in the opening tag <SCRIPT LANGUAGE="JavaScript"> and closing </script> tag or can I just block all the scripts within the one pair of tags?
If so, is their some advantage in so doing - like faster execution of the code. I remember seeing somewhere an article that said 'every time the browser comes across script it has to break off from processing html and so all scripts should be kept together.' Is this correct?
David

gil davis
01-01-2003, 06:21 PM
Originally posted by davidgraham16
... or can I just block all the scripts within the one pair of tags?
You can place all your code inside one set of tags. I don't believe that there is any advantage in not doing so.

There is an advantage in using separate .js files - reusability. That would actually require separate tags, specifying the source.
... an article that said 'every time the browser comes across script it has to break off from processing html and so all scripts should be kept together.' Is this correct?
Someone would have to know the inner workings of the browser, and each brand of browser would do it differently. Obviously, it takes processor time to interpret the tags, but I doubt that eliminating extra tags would speed up the process noticeably.

Rick Bull
01-02-2003, 07:13 AM
The only thing I would say is if you have some functions that don't output content (e.g. document.write), but rather are just called when the user does something like submits a forum, you could put them in a seperate script section and set the defer attribute:


<script type="text/javascript" defer="defer"><!--
function validate() {
//blah blah
}
//--></script>


That way browsers don't have to read through the JavaScript until after the page has finished loading, which may help to speed up your pages. Don't know how well supported it is though.