Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Why do javascript files get inserted before </body> and not within <head>


Reply

3 Posts   1010 Views

Avatar
vwd

28 March 2011 at 6:28pm Community Member, 159 Posts

Hi,

Just wondering why javascript files included using

Requirements::javascript('...')

get inserted before

</body>

and not in

<head>

.

Just curious if there are any advantages of one method over the other.

Thanks.
VWD

Avatar
Nathan Cox

28 March 2011 at 8:47pm Community Member, 99 Posts

It's considered best practice: putting the .js files at the bottom of the page makes them download last which increases overall page loading speed. Check out http://developer.yahoo.com/performance/rules.html#js_bottom

Avatar
vwd

28 March 2011 at 10:45pm Community Member, 159 Posts

Great - thanks very much for that Nathan. I understand now.

VWD.