Not wrapping HTML comments around your embedded code
This achieves two things:
Not delaying the execution of scripts
If you place the code above in the
<head> section of your HTML document, the
The first solution is the simplest, but also the one most prone to error: you simply place any scripts at the very end of your document, just before the closing
</bodytag. This semi-guarentees that it will come in after any
bodycontent, the only possible exception being large files, such as images. that may still be loading. Because of that, the technique is usually combined with one or more of the solutions that follow.
deferattribute to the
<script src=append.js defer></script>
In theory this means that the script will not execute until the DOM has been completely parsed. Right now, browsers implement
deferin slightly different ways, so it is not yet suggested as a complete solution.
tokenOne is a different variable from
TokenOne. Scripts often break because you are trying to test or set the value of a variable that does not exist.
Confusing Concatenation & Addition
+ symbol to achieve their ends. It’s important to remember what you are joining together, how and why, and anticipate the result, in order to avoid errors:
alert(10 + 12);
// result is 22
// result is “102” – note that this is a string, not a numeral
alert(“There is no “ + “cake”);
token = 2;
alert(10 + token)
// result is 12
token = “Two”;
alert (10 + token);
// result is “10Two”
Confusing single and double quotes
// result is Two
// result is Two’s
// result is an error
Not providing a fallback for an externally sourced script, especially a framework
While Google’s servers are unlikely to fail, it is still possible. Sourcing your JQuery from Google has many advantages, but you should always provide a fallback. My preferred solution is the one popularized by Paul Irish’s HTML5 Boilerpate:
This provides a fallback option if Google’s servers are unresponsive; obviously, you must have a copy of the script in the assigned location (a copy of JQuery in /assets/scripts, in the case shown above).