I have a web app that has a universal HTML header include, so I'd like to put page-specific scripts in each page instead of having it load for everything. I tried putting document.ready()
near the end of the <body>
of a page and it seems to be working fine. Are there any potential hazards to putting it there instead of inside the <head>
?
views:
402answers:
2
+2
A:
None. Just make sure everything is loaded in the proper order.
Eric Wendelin
2009-02-03 23:09:03
+5
A:
Yahoo recommends putting all scripts at the end of your document for performance - http://developer.yahoo.com/performance/rules.html
Dan Finch
2009-02-03 23:09:58
I guess I could even put it between </body> and </html>?
Matthew
2009-02-03 23:14:15
Best not - there's not supposed to be anything in html other than head and body-or-frameset. A browser might choose not to execute the code; in any case it certainly wouldn't validate.
bobince
2009-02-03 23:25:11