Mixx’s Engine Room - Stoking the fires at Mixx

Return to Mixx

Hiding content, accessibility, and the onload problem

Posted by Jason on September 15th, 2008

Since I joined the Mixx team (a year and some change ago) and began cranking out the HTML, CSS, and JavaScript that you see and use every day, I made it a point to build features out with accessibility in mind. Mixx has a great variety of users comprising all races, colors, creeds, and capabilities. It was (and remains to this day) important to us that we provide a great experience for our users while not leaving anyone out in the cold.

As most of you know, there’s a ton of interactivity on Mixx—voting, reporting, submitting, interacting with YourMixx—the list goes on. Each of these elements involves a different interaction with the application and every one of them involves manipulating content on-screen using a combination of JavaScript and CSS.

In an effort to accommodate users (or, more directly, their browser of choice) who have JavaScript turned off, we take the approach of displaying all content by default and then using JavaScript to hide the appropriate elements. The easiest to observe example of this is on the permalink pages. With recent redux of the permalinks, we added some new “tabs” (for lack of a better descriptor) below the entry information and above the comments: Activity, About this site, and Related.

When browsing to a permalink page, depending on how zippy your Internet connection is, you may notice that the three tabs are expaned and stacked on top of one another initially. After a brief pause, they’ll snap away and they may then be accessed by clicking on their respective button. This is, at the most basic, the situation described above. Page content loads. JavaScript does its job and hides the appropriate pieces.

In a perfect world, this would happen instantaneously and no one would notice. In the real world, Internet connections are variable, web servers hiccup, and external resources (like Google Analytics) have the side-effect of stalling firing of local scripts. The last point there is the one of concern to our discussion. Steve Souders, in his excellent book High Performance Web Sites, goes into great detail about why this stalling happens. Check out Chapter 6 on “Problems with Scripts.”

So what do we do? Let’s first take a look at how Mixx currently works.

As we’ve observed, our HTML and CSS style everything on the page and display elements by default. Once everything is loaded up, the Mixx JavaScript (using jQuery, a subject for another post) uses $().ready() to fire off our onload events. The appropriate bits hide away and we’re done. This is great as far as “best practices” and all that are concerned, but less-than-great from a perceptual viewpoint.

Robert Nyman, in his post How to hide and show initial content, depending on whether JavaScript support is available, outlines a technique where you add a <script> element to the <head> of your document which calls an anonymous function which, in turn, adds a CSS file to your page. The CSS file contains a single line with a selector (in his case an ID-based selector) that tells an element to not display.

It’s a brilliant solution that overcomes the onload problem introduced by remote assets. The only amendment I would make to his example is to use a class-based rather than ID-based selector. This way, you can set up a single class (”.alt”, for instance) and apply it to all elements you wish to hide.

Simple as that, really. Robert offers us an extensible solution to a problem that’s been troubling developers more and more. So why, then, you ask, has Mixx not implemented this? “Time”, mostly. We’re a small team here with a huge list of things to do! I promise you, though, that this will be implemented as we have time.

Have you found other effective solutions to this issue? If so, leave us a note in the comments!

Add to Mixx!

3 responses to "Hiding content, accessibility, and the onload problem"

  1. Robert Gonia added September 15th, 2008 at 9:28 am

    Nice post thanks. I am eager (believe it or don’t) to try this out.

    Like everyone else in the world (hyperbole?) I have had to deal with this, too. In the past I have used a block with a tag embedded in it. I placed this right before the element I wanted to hide. I don’t like it because it’s ugly and non-valid but it does work. Also heard the suggestion of placing a block with the necessary JS code immediately after the element you want to hide. This latter idea has the merit of being valid (which matters to me), so I like this one. Both of these approaches result in in-lined code of one sort or another, but they do prevent the flash of should-be-hidden-content.

    As far as maintenance goes, if we are correctly templating our sites the fragments that need to hide content on page load will always be near their in-lined code that hides them so in the end I have not found these approaches to be unmanageable.

    Always enjoy reading here. Thanks for the posts.

  2. Jason added September 16th, 2008 at 8:33 am

    Glad you enjoyed my post, Rob.

    I’ve considered the “placing script inline after the element,” but the potential trouble there is that there could be a function call inline that gets fired before the entirety of the included script (in the head) has been loaded.

    I always aim to keep things valid and appropriately separated, but there are certainly times where practicality trumps standards devotion.

  3. Doug added September 19th, 2008 at 6:32 am

    I know this isn’t the real solution but while you mixxers are waiting for the change disucssed above, I suggest the latest webkit (what safari is built on, but the opensource version) build - http://nightly.webkit.org/start/trunk/36640

    It has this javascript engine called “squirlfish extereme” and it is super fast. Yep, faster than the Google’s Chrome.

Add Your Comment

  • (will not be published)
  • (optional)

© 2009 Recommended Reading, Inc. User-generated content is licensed under a Creative Commons Public Domain license.