I've read that it is bad practice, but usually harmless, to place most of a page's <script>
after the <body>
. Since the consequences seem not to be big, I am wondering if I have a compelling reason to try it: page load speed.
My question is: will the pre-body javascript execute any faster if the rest of the javascript comes after the body? Or to put it differently: is the faux document below any faster in loading than if I had placed all the script in the head?
<html>
<head>
<script src="urgent-stuff.js"/>
</head>
<body>
<p>Lots of great content</p>
</body>
<script src="not-so-urgent-stuff.js">
</html>
Note: I am using jQueryMobile for my site (=mobile app). This framework puts the entire site in one document, and dolls up the basic HTML of each page with style and interaction based mostly on element "data-" attributes before that page is shown. The jQM javascript is obviously part of the urgent stuff that goes into the < head >. jQueryMobile has its own 'getting started' event called 'pageinit', which it says fires well before the regular 'document ready' in regular jQuery.