New Perspectives On Web Design

(C. Jardin) #1

CHAPTER 3 The Vanilla Web Diet


Use a Mix of Technologies, Each for What it Does Best
It is very tempting to do everything in JavaScript, but you shouldn’t.
When you have a shiny new hammer, everything looks like a nail —
and turns out to be a thumb once you start hammering. We have incredibly
powerful technologies in the Web stack, the most powerful probably being
JavaScript. CSS is a strong second, considering the recent additions. In
general, it is possible to do everything to and in a browser with JavaScript.
You can create whole applications with just a body tag in your HTML. You
can make outdated browsers behave like their modern versions, you can
interact with windows and the DOM, and move data to and from the serv-
er. Retaining control makes it tempting to do everything with JavaScript.
Whole frameworks have been built on that premise (qooxdoo^2 , for exam-
ple) with amazing performance and great programming principles. Sooner
or later, though, they become outdated and do things in JavaScript that no
longer need to be done at the cost of processor computation.
Remember when we created lots of small images to add rounded cor-
ners to things? And how cool it is now to have CSS border radius and back-
ground gradients to change the look and feel, without needing to recreate
all of them or ensure our users don’t have the old ones cached?
The same thing is happening to JavaScript right now. A lot of what we
use JavaScript (and especially libraries like jQuery) for is now handled by
CSS: transitions, animations, media queries. This allows us to create amaz-
ingly smooth experiences and benefit from the browser working to ensure
they stay smooth. If we use JavaScript, we get more control but our larger
responsibility is to ensure things are smooth. And this responsibility very
much depends on the browser and the technological contexts — contexts
that change from month to month.
One thing that massively slows down apps and websites is DOM
access. Yet the simplicity of jQuery’s DOM access API bred a whole gen-
eration of developers whose first lesson learned was how to write a loop

2 http://qooxdoo.org/
Free download pdf