{Carrer web log} ←
Svetlo - One Line JavaScript Selector Engine
Tuesday, April 12, 2011 { 7 Comments }
I'm working on one new mini JavaScript Framework for building mobile apps.Probably the most critical part of any JavaScript Framework is the selector engine. Naturally the faster is the selector engine the faster will be all the Framework.
Most of the modern selector engines are build upon querySelectorAll because it gives the best flexibility. Little problem with querySelectorAll is the speed.
Traditionally getElementById is much faster then querySelectorAll, but things are changing. Opera 11 has super optimized querySelectorAll and probably all the browsers in the future will try to speed optimize querySelectorAll.
For my (not yet published) JavaScript Framework I've used this code for the selector engine (codename Svetlo).
// Svetlo :
function $(selector){return Array.prototype.slice.call(document.querySelectorAll(selector))}
What this code does is putting the querySelectorAll results "toArray" and that helps the speed optimization. The code is not new I think the first time I saw it on John Resig blog.
I'm not even sure that this line of code can be called selector engine, but I think that it can be helpful to someone and is good baseline for writing JS applications that doesn't need to run in IE. Hint: Web apps for iPhone and Android.
I did some performance test.
The test are based on this principle http://jsperf.com/nodelist-vs-array-iteration
http://jsperf.com/svetlo-class
http://jsperf.com/svetlo-id/3
http://jsperf.com/svetlo/3
If my testing logic is correct result show that this selector engine is faster then the native querySelectorAll and equal like native getElementById method.
If my testing logic is correct result show that this selector engine is faster then the native querySelectorAll and equal like native getElementById method.
This solution will run on of Safari, Chrome, Firefox, Opera and doesn't support IE.
My intention was to build JS Framework for mobile webkit browsers(iOS, Android).
So if you building web app for iPhone, iPad, Android this selector engine can help you, if you need to support IE this selector engine is completely useless.
Other super small selectors:
Ben Alman QSA library
Dan Heberden Quewery
Dustin Diaz Qwery
All comments and suggestion about this small selector will be appreciated!
7 Responses to “Svetlo - One Line JavaScript Selector Engine”
- // // 4/12/2011
- // Vladimir // 4/12/2011
- // psayre23 // 4/13/2011
-
// Vladimir
// 4/14/2011
@psayre23: You will have some small speed improvements by adding the "body" function $(selector) {return Array.prototype.slice.call( document.body.querySelectorAll(selector))} or by mixing with getElementById in some cases: function $(id,selector){return Array.prototype.slice.call(document.getElementById(id).querySelectorAll(selector));}
- // // 4/15/2011
- // Vladimir // 4/15/2011
-
// buytwitterfollowers
// 5/25/2011
Loved the post but the point you make is a good one.
branqueamento dentário
<< Home
About Me <<<
Name: Vladimir Carrer
vladocar [at] gmail.com
Location: Verona, Italy
I'm a web designer, developer, teacher, speaker, generally web addicted ...
My projects <<<
- AI Prompt Directory
- Hand Drawn Icons
- Font Design Inspiration
- Font Pairings
- Free SVG Cut File
- Upcoming NFT projects
- Discord Tutorials
- Free Sublimation Designs
- Tech Feed
- MySQL Lite Administrator
- Quark Mini PHP CMS
- Formy - CSS Form Framework
- Emastic - CSS Framework
- Malo - CSS Library
- The Golden Grid
- 1 line CSS Grid Framework
- Two Lines CSS Framework
- Child Selector System - CSS Framework
- Better Web Readability Project
- Azbuka - CSS Typographical Base Rendering Library
- ClipR - bookmarklet for better reading
- CSS3 Action Framework
- CSS Mini Reset
- HTML5 Mini Template
- CSS Mobile Reset
- picoCSS - JavaScript Framework
- HTML Lorem Ipsum Crash Test
- Object Auto Documentation - JavaScript
- o - JS Library for Object Manipulation
- Foxy - CSS Framework
- Tumblr Free Theme - Better Readability Project
- Box - CSS Framework
- SMART CSS GRID
- nanoJS - Minimal JS DOM Library
- Flexy CSS Framework
- Katana is CSS Layout System made with Flexbox
- Micro CSS Reset
- 60 Grid System
- Simple CSS Button
- ramd.js JavaScript library for making web applications.
- Minimal Notes web app build with Vue.js
- Scribble Font for Prototyping & Wireframing
- Flex One - 1 CSS Class System
- Floaty - CSS Float Based Layout System
- Infinity CSS Grid
- CLI Convert websites into readable PDFs
- keywords-extract - CLI tool, extract keywords from any web page.
- screenshoteer - Make website screenshots and mobile emulations from the command line.
- Basic.css - Classless CSS Starter File
§§Previous Posts <<<
- Child Selector System - CSS Framework
- About Repaint and Reflow in JavaScript
- Better Readability Project - Free Tumblr Theme
- CSS3 Chat Bubbles
- Line length and Font Size relation in design
- Safari - open links in new tabs
- Hacker News Mobile (Front Page Reader )
- CSS Mobile Reset
- About JSONP in JavaScript
- Two Lines CSS Framework
Other Profiles <<<
Content is licensed under a Creative Commons Public Domain License