Perfection kills

Exploring Javascript by example

Feature detection all the way

December 9th, 2008 by kangax

I have been working on a little personal project of mine for the past couple of months. It’s called CFT and stands for Common Feature Tests. There’s nothing really ground-breaking about it; CFT is simply a set of so-called feature tests for Javascript (or rather for any ECMAScript-compliant flavor - be it Microsoft’s JScript, Mozilla’s JavaScript or WebKit’s JavaScriptCore engines).

These tests aim to detect all kinds of quirks that modern (and not so modern) browsers exhibit and detect those quirks in the most straight-forward way - using feature detection rather than browser sniffing. There are quite few excellent resources out there on a subject of “browser sniffing vs. feature detection”. It’s definitely worth checking them out.

CFT started as an initiative to replace as many unnecessary browser sniffing from Prototype.js as possible (now that I’m part of the core, I feel bound to do something useful for the library :)). The suite was then extended with other tests that seemed not quite trivial to implement.

I really hope CFT helps developers eliminate browser sniffing code plaguing their scripts. The project is under an MIT license and is hosted on github (although is still in its infancy).

As always, any bugs/suggestions are greatly appreciated.

Categories: cft

Comments (10)

  1. Gravatar

    staaky said:

    Nice work. Good move on githubbing this. I remember you mentioned the feature tests on the mailing-list. Back then I tossed in the idea to not run tests upfront http://gist.github.com/24895. Could work for you here with something like CFT.test to help make this more interesting to frameworks once it grows. Keep it up!

  2. Gravatar

    Diego Perini said:

    Excellent Juriy,
    thank you for sharing, I have great use of your "feature testing" in my projects not all of them obviously, the ones having to do with IE mostly, events and selectors.

    Browser bifurcations in frameworks will finally work as intended :-)

    --
    Diego

  3. Gravatar

    kangax (article author) said:

    @staaky, @Diego
    Thanks : )

    @staaky
    We can definitely play with your proposal in a near future. Having a generic method to run particular test at runtime could be helpful in cases when running them all at load-time is not an option. Mind creating a fork?

  4. Gravatar

    staaky said:

    Kay, when I find some time I'll experiment with a fork. The other benefit of the proposal is that the results are cached so tests only have to run once.

  5. Gravatar

    Zach Leatherman said:

    Another good test might be for the resize event. Does it fire when the resize is complete, or at the frequency in which rabbits procreate?

  6. Gravatar

    lars said:

    hey, saw your comment on my site. try the videodrive maybe that someone else commented on, i havent tried it myself but my guess it should work better

    http://www.aroona.net/VideoDrive/Home.html

    cheers!

Trackbacks

  1. Ajaxian » Common Feature Tests said:

    [...] has written about his new Common Feature Tests [...]

  2. Technology said:

    [...] has written about his new Common Feature Tests [...]

  3. Common Feature Tests | Slightly Nervous said:

    [...] has written about his new Common Feature Tests [...]

  4. Css howto » Common Feature Tests said:

    [...] has written about his new Common Feature Tests [...]

Leave a Comment

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Please, don't forget to escape your input (<, > and &). Wrap code sections with <pre>