Eric Pascarello wrote:That is incorrect. You can add external script references in the body. A good rule of thumb is to include your scripts before the close of the body tag and not in the head.
Eric, I was curious... why would you place the script inclues near the bottom of the close body tag? That sounds like a terrible idea, I would think all imports, includes, etc would go at the top just like Java, VB, C++, C#, CSS, etc etc.... I'm sure there must be a reason, right?
I'm not sure what Eric is getting at, but I'm sure he'll elaborate.
A lot of people put their script at the bottom of the file to achieve this, and I'm not sure that's what Eric is getting at, but I think it's a poor practice.
Disclaimer: I sometimes place script tags in body when loading dynamic content via Ajax with jQuery (whose Ajax methods know how to trigger their execution).
Joined: Nov 07, 2008
Thanks Bear, that's probably what he's getting at. I haven't worked with DOM's yet so it is not an issue for me yet. ;)
Also, you said "to make sure no script executes until after the DOM has been built"... this would only apply to script that does not have an onClick or other event associated with it right? I mean, as long as it has an event associated with it that requires user interaction then it won't get ran before the DOM gets built right?
Joined: Nov 08, 2001
There is a lot of things you can do with performance with websites on the front end and may see a little strange, but browsers do some strange things with loading files. If the JS files are really big, it can hang up the browser. Perceived loading times are a lot better than actual loading times. Look at windows!
I have done Web Page performance for my one job and when you can make things seem faster, you do it.