Loading JS at the end of the document.

JavaScript related questions should go here.
Post Reply
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Loading JS at the end of the document.

Post 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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Loading JS at the end of the document.

Post 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.
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: Loading JS at the end of the document.

Post 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:
Post Reply