What order is JavaScript executed in a browser?

Associate
Joined
24 Jun 2006
Posts
1,462
I'm trying to optimise my pages as much as possible which means trying to move the JS includes to the bottom of the page.

There are one or two pages on the site that require inline JavaScript.

Does anyone know if a browser will try and execute this before the includes have loaded?

I'm using jQuery so most stuff is already wrapped in:

Code:
jQuery(document).ready(function() {
});

Cheers!
Paul.
 
Why move them to the bottom of the page? I see no benefit from this. Leave them as link tags in the header, where they are meant to be :p
 
Meh.. premature optimisation tbh. I'd much rather I kept my script(s) in head than save a few peco-seconds of load time. :)
 
The difference that will make is negligible - especially if the script has been cached. that Yahoo article suggests that most browser can only download 2 items in parralel - this is false. Most of the mainstream modern browsers can do more than this, Firefox for example allows 6.

Anyway, back OT. The order JS is executed is dependent on the page, and the events the code is attached to.

The easiest way to test is to put an alert into each function and note down the order in which they appear.
 
Anyway, back OT. The order JS is executed is dependent on the page, and the events the code is attached to.

The easiest way to test is to put an alert into each function and note down the order in which they appear.

Cheers! Well every little helps on a large site and depends whether or not the JS is set to cache or not.

Also noticed http://www.smu****.com/ysmush.it/ which knocked the page weight down a fair bit.
 
Back
Top Bottom