Tuesday, July 22, 2008

Unobtrusive Javascript and . . . a paper towel dispenser???

I've got two ideas for a blog entry, and can't decide which one to write first: the paper towel dispenser story, or the unobtrusive Javascript example. Oddly, the more I think about them, the more interconnected they seem. So, let me take a preliminary stab at this.

Think about a paper towel dispenser in a public restroom for a moment. We wash our hands, pull out a paper towel, dry our hands and throw away the paper towel without much thought. The only time we even think about the people who fill the paper towel dispenser is when they fail to get refilled, right?

I want you to imagine this guy-- his name is Dan. Dan works at an establishment with a public restroom, and part of his job duties is to make sure that the paper towel dispenser never runs out of paper towels. Dan has other job duties though; he can't just sit in the bathroom and watch the paper towel dispenser. So, first thing every morning, he stuffs the dispenser with as many tightly stacked paper towels as he can. His reasoning, of course, being that it will take more time for people to work their way through a bigger/more numerous pile of paper towels than a small/less numerous pile-- which also means he won't have to check it and refill it as often.

Less work for Dan means it's better, right?

That is, until you discover the paper towels are so tightly stuffed into the dispenser that patrons are finding it difficult to get them out. They grab the first one, but it doesn't pull free, gets wet and then tears apart in their hands. So, customers wind up pulling out a second paper towel to dry their hands with a whole piece instead of the torn fragments. Now every customer is using two paper towels instead of one.

You don't want to stuff the paper towel dispenser with as many paper towels as human possible. You want to make sure it never runs out, but you also want to make sure it allows people to easily remove a paper towel when their fingers are wet.

So, where does the unobtrusive Javascript come in, you're wondering? (That makes two of us.)

Web developers need to put Javascript into their web sites in much the same way that the paper towels need to inserted into the towel dispenser. Keep it "loose" and make it superfluous. When people can't get around your site and make use of its core functionality with their Javascript turned off, you've tried to cram too much Javascript code in there.

No comments: