adequately good

decent programming advice

written by ben cherry



all articles filed under performance

Saner HTML5 History Management

Included in the laundry list of new features that are descending on the world of web development with HTML5 are two quite nice ones: History Management and the hashchange event. These two features allow for much richer and faster JavaScript applications. Let's start with a quick overview of what these provide.

Hashchange

This event is quite simple. Whenever the window.location.hash property changes, by following a ...

Performance of === vs. ==

One particular weirdness and unpleasantry in JavaScript is the set of equality operators. Like virtually every language, JavaScript has the standard ==, !=, <, >, <=, and >= operators. However, == and != are NOT the operators most would think they are. These operators do type coercion, which is why [0] == 0 and "\n0\t " == 0 both evaluate to true. This is considered, by sane people, to be a bad thing. Luckily, JavaScript does provide a ...

Minimum Timer Intervals in JavaScript

I was talking with a co-worker today about the behavior of setTimeout and setInterval when given a small interval, like 0 or 1. The expectation would be that the timer will fire in 0ms, or 1ms. However, as with other things in JavaScript, the reality is a bit different. It turns out that browsers actually have a minimum timer interval which they can't work any faster than ...

Preloading JS and CSS as Print Stylesheets

UPDATE: This technique has turned out to be dangerous in Chrome. It seems that Chrome will load the JS files into the cache, but then set an implied type="text/css" on them. This means that it will refuse to re-use them as JavaScript on future pages, until they have left the cache. I can no longer recommend this technique, but hope that it was at least interesting ...