Thursday, April 24, 2008

Javascript, content and navigation

One error in judgment that many web developers make is assuming that everybody is running javascript, and therefore it's OK for js to present content or navigation. To the extent that if javascript isn't running content and nav don't show up.

This is a bad idea. First, you have to divorce yourself from the idea that your most important audience is humans viewing pages on a web browser. Google's spider isn't running javascript. If your navigation isn't present in the markup, it can't crawl your site. And if your content isn't there, there's nothing for users to search. And some people don't view web pages. A program speaks it's content to them. Screen readers read the content that's present onload. If you run javascript after page load, the screen reader doesn't see the update and skips the content. There goes your accessibility, which is mandated by laws in some places. Further, mobile browsers are more ass than a donkey farm. Most don't run javascript, so there goes most people in the world when they're not at home. Your audience is software programs that mediate a users web experience. Code to them first.

Second, pobody's nerfect. If your script barfs then the user is S.O.L. It may work perfectly in dev and when it launches. Then a site user adds malformed content in a blog reply, the people who hired you to make the site paste in markup from MS word or some other such mishap and the page isn't what you assumed it would be when you created the script. You have to plan for your site to degrade gracefully. If for some reason the script doesn't run, the CSS doesn't get applied, the site should still be navigable and the content should still be available. Bells and whistles may not work... but the website should still function as a collection of hyperlinked pages with content.

So, I wouldn't say depending on JS to display nav and content is a pet peeve per se as much as it's an example of not adhering to best practices.

No comments: