There's a growing concern of mine revolving around the desire to use JavaScript in conjunction with, or in replacement of, XHTML-based navigation on websites. There are a lot of resources out there investigating the use of JavaScript with regards to search engine performance, web accessibility, and web interoperability. I'm going to try and summarize my thoughts here, and establish general guidelines to a healthy use of JavaScript with website navigations.
IntroductionNavigation is such a vital piece of your website. It provides your users with a tool to move around and discover your content. As web professionals, we use navigation to predefine a structural organization of website content.
Jakob Nielsen, web usability guru, suggests that:
Amen, brother. A well-constructed and contextualized navigation for your website can make or break your users' experience. Too much navigational information will confuse the user, and not enough will confuse the user. There's a middle ground, and it's different for every website.
At my company, we primarily build websites for – or in support of – newspapers. Newspapers have a long-standing traditional navigation structure, but they're optimized for print. We hold the responsibility to translate these navigational structures into something useful for web users.
It's easy to see how vital a well-constructed navigation can be to the success of your website. Ultimately, it's your job to make sure the user understands the website structure and is not prohibited in any fashion from doing so. Barriers include informational overload, readability, and – for the sake of this article – technological hurdles.
Using JavaScript with website navigationAt a high-level, there are two ways JavaScript can be used with navigation:
A typical use of JavaScript to enhance the user experience would be to provide behavioral functionality in support of showing or hiding navigational menu items. Examples of this would include dropdown menus and / or displaying content's location within a hierarchical structure of other content. To fall into this category, the JavaScript should be unobtrusive to the overall user experience.
Unobtrusive JavaScript is a technique used to more strictly adhere to the behavioral nature of JavaScript as a scripting language. According to the technique, JavaScript should be used in circumstances where:Now, there are many stable CSS alternatives to providing behavioral functionality for navigation, but I'm not going to get into them.
Providing the user experienceIn contrast, using JavaScript to provide the entire user experience presents several problems. The definition of 'providing the user experience' would be something to the effect of using JavaScript to generate an XHTML navigation on the fly from, perhaps, a JSON object.
As I've pointed out above, doing so would be in direct violation of several principles in that:
Thus, using JavaScript to solely provide the user's navigational experience is never recommended.
The effect on search engine optimizationGoogle has been making great strides towards indexing Flash and JavaScript generated content, but it's still not an exact science.
If JavaScript is used as it is intended as a behavioral layer to provide additional user experience elements (coined 'progressive enhancement'), the structural markup of a page should still contain the information that search engines are looking for.
In the event that JavaScript is intended to enhance the user experience with an already defined XHTML structure on the page, no search engine performance degradation should occur.
However, in the event that the entire navigational structure of a website is defined in JavaScript and later interpreted into an XHTML structure on the page, it should be expected that serious search engine performance degradation will occur.
Web accessibilityDeveloping navigation solutions with JavaScript techniques not only takes a toll on SEO, but more importantly on web accessibility.
Adherence to web accessibility guidelines is vital to the usability of your website by users with screen readers, speech recognition software, and other assistive technologies. The availability and usefulness of JavaScript to these users is often limited, and your design teams must take this into consideration.
The mobile effortThe mobile web has come a long way in recent times, and while it is suggested that mobile strategies are not simply mirrored from desktop strategies, it should be noted that mobile phones traditionally (sans-iPhone) have little support for JavaScript.
If you're truly interested in delivering a quality mobile web product, read Cameron Moll's book, Mobile Web Design, and give Pete a shout.
Performance and page load timesAs stated, JavaScript is intended to be a solution for providing a level of behavioral improvement to a website. Since JavaScript is a client-side scripting language, it relies on the web browser to process the script. Thus, JavaScript should not be rendered until the webpage has completed loading the XHTML onto the page. Unfortunately, this often means a period of loading time is associated with the rendering of the script.
Excessive amounts of JavaScript can also have serious performance issues, especially, for example, when parsing a large JSON object for manipulation into an XHTML navigation structure.
ConclusionAny JavaScript technique used to enhance the user's experience with navigation should be very carefully implemented. Be absolutely sure there's no way to accomplish what you want with other, more friendly, means such as CSS.
If you must use JavaScript to enhance the user's experience, do so paying close attention to the guidelines set forth by the W3C and the ideals of progressive enhancement.
Finally, never, ever use JavaScript to single-handedly provide the navigation for your website.
4 Comments
Is there any way whatsoever for Google to interpret navigation that's been generated using JavaScript?
There must be examples of sites that generate their navigational structure after the page has loaded. Those sites _must_ still get SEO benefits? right?
> Is there any way whatsoever for Google to interpret navigation
> that's been generated using JavaScript?
In my travels, I've found no such evidence that Google consistently crawls all content generated by JavaScript.
Google specifically makes a point to developers that if you want your content crawled, it damn well better be in XHTML.
I would love to hear arguments otherwise, if there are any.
> There must be examples of sites that generate their
> navigational structure after the page has loaded. Those sites
> _must_ still get SEO benefits? right?
I don't think so. Perhaps someone who has written their entire navigation in JavaScript will kindly chime in here.
Nick
We're considering using JSON for our navigation. We build sites for various businesses based on a single codebase. We're going to be doing lots of code generationto HTML which means we lose the benefits of having a server side include of some sort.
We'd like to be able to offer both CSS and Flash based navigation and a JSON file seems to be the logical offering for this. I've tasked our SEO department (all of them Google, Yahoo, and MSN certified) with research as to the merits of this approach.
@Andy,
Good luck :)
Nick
Post new comment