Chapter 5. Best Practices

What this chapter covers:

  • Graceful degradation: ensuring that your web pages still work without JavaScript

  • Unobtrusive JavaScript: separating structure from behavior

  • Backward compatibility: ensuring that older browsers don't choke on your scripts

  • Performance considerations: making sure that your script is performing at its best

Together, JavaScript and the DOM form a powerful combination. It's important that you use this power wisely. This chapter describes some best practices that you can use to ensure that your scripts don't do more harm than good.

Mistakes of the past

Before we get to the specifics of best practices for having web pages work correctly, let's take a quick look at some reasons that things can go wrong.

Don't ...

Get DOM Scripting: Web Design with JavaScript and the Document Object Model, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.