Chapter 6Producing Lean Web Assets: Part 1
Warm Up
While the previous chapter explored techniques for reducing and optimizing HTTP requests in general, this chapter will focus on optimizing individual web assets such as HTML, CSS, and JavaScript.
Optimizing HTML
When writing HTML, make sure it is semantic, valid, and as lean as possible. The more errors your code contains, and the more nested elements you have, the more work you are requiring of the browser. (The browser will do its best to correct your errors as it constructs the DOM, but there's only so much it can do.)
Move any inline styles from HTML elements into your style sheets.
For example, instead of writing <div
style="color:red">
, use div {color:red}
in
a separate style sheet.
Get Lean Websites 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.