i am dustin diaz

a JavaScriptr...

boosh.

don't worry about it.

Qwery - The Tiny Selector Engine

Thursday Mar 24 2011

It's true. The world needs another JavaScript DOM Selector Engine. So without further fuss - introducing Qwery - The Tiny Selector Engine. It's a port from where Simon Willison left off with his getElementsBySelector in 2003, and believe it or not, this is exactly where jQuery started.

Qwery supports all the basic CSS1 & CSS2 selectors, plus the additional (most important) attribute selectors from CSS3. Additionally it allows multi-selects (div,p) as well as context-aware selectors (like jQuery.find()).

Last but not least, it's open source awaiting your valuable feedback to make it leaner and faster. There are tests to ensure its integrity, however sans-benchmarks. Although, it should be noted it does support querySelectorAll when available in the browser (to bring 2003 to modern times).

Why all this?

When it comes right down to it, you often don't need a full blown selector engine suite. Qwery is 1k (gzip+min) which comes out to 1/4 the size the Sizzle. And on a day to day development basis, it's pretty rare to be seeking an obscure element collection from a query like div > p:lang:(en):nth-child(1n+0):not([data^="user-"]) . Seriously, who does that? (Maybe 2% of you are raising your hand).

Real world css queries

To put things into perspective, building #NewTwitter didn't require a single complicated CSS query beyond attribute selectors to retrieve data on nodes (which Qwery supports). Other than that, most queries were simple element/class descendent selectors. That being said, given the complexity of the application it's safe to say most applications will never need anything beyond what Qwery provides. So have at it and give it a play

Contributors

Cheers.

this is who i am

Hi, my name is Dustin Diaz. Nice to meet you, too. I (actually) build products. Currently founder of an Expa-backed company. Previously @Change, @Medium, @Twitter, @Google, and @Yahoo. I wrote a book called Strobist® Info and was co-author of JavaScript Design Patterns. I co-created the Ender JavaScript Framework, I was an award-winning Photographer, and I pretend to be an amateur Mixologist. Pretend is fun. This is my website. Welcome!

On this site I (used to) write about JavaScript. You can also follow along with my open-source work on Github.

Last but not least, recruiters, you are very kind. I’m not looking for work. Cheers.