Page 1 of 1

Loading JS at the end of the document.

Posted: Mon Jun 11, 2012 4:56 pm
by EcazS
Is there a real reason for having JS files "included" in the end of the body versus in the head?
Except for the fact that if you have it in the head you have to check if the document is ready.

Re: Loading JS at the end of the document.

Posted: Mon Jun 11, 2012 5:00 pm
by jacek
If they are at the end they load after the HTML, meaning the browser can display the page before it has to wait for the scripts to download. If you have a lot of JS files and a slow server your load time can suffer since they have to be downloaded and processed one at a time.

That's my understanding of it anyway.

Re: Loading JS at the end of the document.

Posted: Mon Jun 11, 2012 5:06 pm
by EcazS
I was looking through a bunch of frameworks and boilerplates and I didn't quite understand why they would always load it at the end.

Those frameworks and boilerplates were developed for mobile sites so I guess it makes sense to have it at the end, I should have been able to figure that out... eventually :roll: