Question

When I first read the principle of unobtrusive JavaScript in the Web Standard Curriculum I thought it's a really great thing.

Unobtrusive JavaScript is more of a programming philosophy than a technique. By far its most important component is a clear sense of which functionality belongs in which layer. All absolutely crucial site functions should be coded in plain HTML, but once you’ve created that base you can add a JavaScript layer on top of the basics in order to give browsers that support it a nicer, cleaner, faster-seeming interface.

Further, unobtrusive JavaScript:

  1. separates structure and behaviour, in order to make your code cleaner and script maintenance easier

  2. pre-empts browser incompatibilities

  3. works with a clean, semantic HTML layer

For my current project I use this approach. When I turned JavaScript off for some other kind of work I had to do I was surprised how many websites are completely broken without JavaScript: missing functionality, as well as absent of a lot of important information, which were not present at all in the whole DOM.

These were especially social network sites. It should be no surprise that this were the case, the required development time and user experience might be a lot more important than the accessibility.

Still I am asking myself, whether unobtrusive JavaScript is not out of date. I mean which browser does not support JavaScript already natively? Is it still an approach which fits for the year 2012? I started doubting it.

Was it helpful?

Solution

There are two ways of approaching a website and the use of JS:

  1. JS as an enhancement

    These types of sites are like "documents" in a sense that they are analogous to newspapers, books and letters. You don't need fancy effects to read and use the content. And with this comes progressive enhancement: Building a basic functionality and add on complexities without sacrificing the purpose.

    Most (large) websites use this scheme to preserve its usefulness even when using a non-capable browser. An example is StackOverflow, which even works on a lynx command-line browser!

     ______
    | JS   | - JavaScript for (optional) enhancements
    |------|
    | CSS  | - CSS for (optional) style
    |------|
    | HTML | - (mandatory) HTML with base content
    '------'
    
  2. JS as a platform

    For web apps, it's reasonable (more like mandatory) that they are build upon JS for real-time, dynamic content and functionality while HTML and CSS serves as the view. It's synonymous to other programming languages, where you can go "headless" with your program (no UI) like libraries and plugins.

    Graceful degradation comes with this approach: "Backwards support only to a certain extent, otherwise you get none at all"

     ____________
    | HTML | CSS | - (optional) HTML and CSS view
    |------------|
    |     JS     | - (mandatory) JS platform
    '------------'
    

It generally boils down to a question of "Is it a document, or an app?"

OTHER TIPS

Different companies take different approaches. For example Google for their search uses unobtrusive javascript which degrades gracefully, but for GMail they maintain a separate HTML only site which they developed later after GMail JS version.

To me it depends on

  1. Complexity
  2. Functionality,
  3. Cost
  4. Impacted user count

to decide whether to do Graceful degradation using unobtrusive JS or to build a dedicated HTML only site or to ignore that user base completely.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top