• Stars
    star
    178
  • Rank 214,989 (Top 5 %)
  • Language
    HTML
  • Created over 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

benchmark for various JavaScript libraries for generating CSS selectors

CSS Selector Generator Benchmark

This is an attempt to create a benchmark for various JavaScript libraries for generating CSS selectors. It is inspired by @dandv's question.

Usage

npm install
npm test

index.html should open in a browser tab with further instructions.

Results

@antonmedv finder

  • NPM package, written in TypeScript
  • no dependencies
  • has tests
  • has documentation
  • MIT license
  • slower speed than other libraries (still fast enough for regular use)
  • creates efficient and robust selectors using ID, class, tags and child marker
    • does not seem to support attribute selectors
  • generates shortest selectors among all tested libraries

Longest selector:

.block:nth-child(3) li:nth-child(2) > .icon-eye-open

@autarc optimal-select

  • supports UMD (Browser & Node)
  • no dependencies
  • no tests
  • MIT license
  • allows single and multiple input elements
  • separate handling of selection and optimization (export ES2015 Modules)
  • creates efficient and robust selectors using ID, class, attributes, tags and child marker

Longest selector:

.clearfix:nth-of-type(3) li:nth-of-type(2) .icon-eye-open

@bimech ellocate.js

  • supports Bower
  • depends on Jquery
  • has tests
  • has documentation
  • no license
  • average speed
  • uses ID, class and tag selectors
  • WARNING: doesn't use nth-child selectors, so it produces a lot of non-unique selectors

Longest selector:

html > body > div > div#wrap > div#main > div.container > div.main-content > div.row > div.span12 > div.row > div.span4.sidebar > div.block.clearfix > div.block-header.clearfix > div.block-action > a.btn.btn-success.btn-small > i.icon-plus.icon-white

Chromium's DOMPresentationUtils

NOTE: Used version on NPM adapted for use in browser.

  • supports NPM
  • no dependencies
  • no tests
  • has documentation
  • see source code for license
  • average speed
  • uses ID, class, tag, attribute (for inputs) and nth-child child selectors
  • WARNING: produces a lot of non-unique selectors in both optimized and non-optimized version

Example of non-unique selector:

div#main > div > div > div > div > div > div.span4.sidebar > div.block.clearfix > div.block-content > ul > li.show-all > a

[
  <a href=​"/​organizations">​Show all​</a>​,
  <a href=​"/​topics">​Show all​</a>​,
  <a href=​"/​topics?scope=starred">​Show all​</a>​,
  <a href=​"/​topics?scope=public">​Show all​</a>​
]

Longest selector:

div#main > div > div > div > div > div > div.span4.sidebar > div.block.clearfix > div.block-content > ul > li:nth-child(1) > a

@desmondw snowflake

This is a Chrome extension, not a stand-alone library.

  • average speed
  • uses combination of tag and class or nth-child

Longest selector:

div.span12 > div:nth-of-type(1) > div:nth-of-type(1) > ul:nth-of-type(1) > li:nth-of-type(10) > div:nth-of-type(1) > div:nth-of-type(2) > span:nth-of-type(1)

@fczbkk css-selector-generator

  • supports Bower and NPM
  • no dependencies
  • has tests
  • has documentation
  • Unlicense license
  • tries to use optimized ID, class, tag child selectors or their combination, uses nth-child as fallback

Longest selector:

.span12 > :nth-child(1) > .span8 > ul > :nth-child(1) > :nth-child(1)

@jhartikainen dompath

  • no support for Bower or NPM
  • no dependencies
  • has tests
  • has documentation
  • no license
  • very fast
  • uses ID or tagg + nth-child child selector, so the selectors tend to become quite long

Longest selector:

#main > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > ul:nth-child(2) > li:nth-child(10) > div:nth-child(2) > div:nth-child(2) > span:nth-child(4)

@martinsbalodis css-selector

Sorry, I wasn't able to make it work.

@ngs jquery-selectorator

  • supports NPM and Bower
  • depends on Jquery
  • has tests
  • has documentation
  • MIT license
  • very slow
  • generates selectors using Jquery's :eq() selector, so most of the results are not valid CSS selectors and are only usable within Jquery

Longest selector: n/a

@olivierrr selector-query

  • supports NPM only
  • no dependencies
  • no tests
  • has documentation
  • MIT license
  • quite fast
  • generates the most complex descendant selector for each element (ID, class, tag, nth-child), so it produces the longest selectors among tested libraries
  • WARNING: uses descendant selectors instead of child selectors, so it sometimes produces non-unique selectors

Longest selector:

#main div.container:nth-child(1) div.main-content:nth-child(1) div.row:nth-child(1) div.span12:nth-child(1) div.row:nth-child(1) div.span4.sidebar:nth-child(2) div.block.clearfix:nth-child(2) div.block-header.clearfix:nth-child(1) div.block-action:nth-child(2) a.btn.btn-success.btn-small:nth-child(1) i.icon-plus.icon-white:nth-child(1)

@rishihahs domtalk

  • supports NPM only
  • no dependencies
  • has tests
  • has documentation
  • MIT license
  • very fast
  • uses ID or nth-child descendant selector, selectors are of average length
  • WARNING: uses descendant selectors instead of child selectors, so it produces a lot of non-unique selectors

Longest selector:

#wrap *:nth-child(1) *:nth-child(1) *:nth-child(1) *:nth-child(3) *:nth-child(1) *:nth-child(1) *:nth-child(1) *:nth-child(3) *:nth-child(11) *:nth-child(1) *:nth-child(1)

@stevoland CSSelector.js

  • supports NPM (claims to support Bower, but I could not find it in the registry)
  • supports AMD
  • no dependencies
  • no tests
  • has documentation
  • MIT license
  • very fast
  • uses ID or tag + nth-child child selectors, selectors are quite long

Longest selector:

#main > DIV:nth-child(1) > DIV:nth-child(1) > DIV:nth-child(1) > DIV:nth-child(1) > DIV:nth-child(1) > DIV:nth-child(1) > UL:nth-child(2) > LI:nth-child(10) > DIV:nth-child(2) > DIV:nth-child(2) > SPAN:nth-child(4)

@thomaspeklak get-query-selector

  • supports NPM only
  • no dependencies
  • no tests
  • has documentation
  • looks like BSD license
  • very fast
  • uses ID or nth-child child selector, selectors are of average length

Longest selector:

#wrap>:nth-child(1)>:nth-child(1)>:nth-child(1)>:nth-child(3)>:nth-child(1)>:nth-child(1)>:nth-child(1)>:nth-child(3)>:nth-child(11)>:nth-child(1)>:nth-child(1)

@tildeio selector-generator

  • no NPM or Bower
  • requires RequireJS
  • has tests
  • no documentation
  • looks like MIT license
  • very fast
  • uses tag or tag + nth-child child selectors
  • WARNING: produces a lot of non-unique selectors

Longest selector:

html > body > div > div > div > div > div > div > div > div > div:nth-of-type(2) > div:nth-of-type(2) > div:nth-of-type(2) > ul > li:nth-of-type(2) > a

TODO

It would be nice to automate the process, run the tests in PhantomJS, etc. Pull requests are welcome.

Bug reports, feature requests and contact

If you found any bugs, if you have feature requests or any questions, please, either file an issue at GitHub or send me an e-mail at [email protected]

More Repositories

1

css-selector-generator

JavaScript object that creates unique CSS selector for given element.
TypeScript
533
star
2

fecal

Simple JavaScript library for people who frequently mistype Array methods `pop()`, `shift()` and `unshift()`.
JavaScript
36
star
3

UrlMatch

JavaScript object that provides URL matching functionality using patterns similar to what is used in extensions in Google Chrome.
JavaScript
28
star
4

workshop-js-principles

Podklady pre účastníkov školenia Princípy JavaScriptu.
JavaScript
26
star
5

koderske-testy

24
star
6

Savedeo-Extension

Browser extension that allows you to easily download videos from popular video sites (e.g. YouTube, Vimeo, etc.). Works with Google Chrome and Mozilla Firefox.
CoffeeScript
13
star
7

isvisible

Cross-browser function that checks if an element is visible.
JavaScript
12
star
8

github-issues-extension

Browser extension that adds handy tweaks for issues at GitHub.
CoffeeScript
10
star
9

firefox-addon-snippets

Firefox Addon Snippets
JavaScript
10
star
10

angle-js

Simple JavaScript library for working with angles.
JavaScript
7
star
11

workshop-vue-basics

Podklady k školeniu Vue.js prakticky
Vue
7
star
12

develcz2013

Podklady k prednáške na Devel.cz 2013
JavaScript
7
star
13

workshop-scope-closure

Unconventional slides for a workshop about scope and closure in Javascript.
JavaScript
7
star
14

frontendisti-npm

JavaScript
6
star
15

cookie-manager

Reusable module for cookie management in Firefox SDK (Jetpack).
JavaScript
6
star
16

workshop-automation

Podklady pre účstníkov kurzu "Automatizace s Grunt, Bower, Yeoman"
JavaScript
6
star
17

Mouse-Pointer-Double

Simple Chrome extension that creates duplicate of mouse pointer on a page. It is intended to use with Chromecast, so that you can see the mouse on the projected page.
CoffeeScript
6
star
18

workshop-js-tools

Podklady pre účastníkov školenia Nástroje JavaScriptu.
JavaScript
5
star
19

talk-2021-09-22-webexpo-codemod

JavaScript
5
star
20

devfest2012

Praktické ukážky kódu rozšírení pre Chrome prezentované na DevFest 2012 v Prahe
JavaScript
5
star
21

develcz-2017-tree-shaking

Podklady k prednáške pre konferenciu Devel 2017.
JavaScript
4
star
22

event-bridge

Bridge object for cross-browser working with events.
JavaScript
4
star
23

chrome-extension-snippets

Chrome extension snippets
JavaScript
4
star
24

webinar-webpack

JavaScript
3
star
25

export-music-list-extension

Browser extension that exports list of all songs from a library in Google Music.
CoffeeScript
3
star
26

2021-05-29-frontendisti-eslint

Podklady k prednáške na konferencii Frontendisti.
JavaScript
3
star
27

the-box

JS objects for working with DOM boxes.
JavaScript
3
star
28

chrome-flags

JavaScript
3
star
29

2022-webexpo-async

JavaScript
3
star
30

javascript-snippets

Collection of handy JavaScript code snippets.
JavaScript
3
star
31

iselement

Utility function that returns `true` if referenced object is DOM element.
JavaScript
2
star
32

update-json

NodeJS module for updating JSON files.
JavaScript
2
star
33

browser-extension-czech-months

Browser extension that adds normal translation to Czech month names.
JavaScript
2
star
34

uuid4

Generator and validator for Universally Unique Identifier v4 (random).
JavaScript
2
star
35

parse-relative-time

Parse simple relative time in human readable format to milliseconds.
JavaScript
2
star
36

intersectarrays

JavaScript function, that creates array containing values, that are present in all provided arrays.
CoffeeScript
2
star
37

browser-extension-mimi-tourette

JavaScript
2
star
38

get-nested-property

Get specific property of nested object, without the need for checking each step separately.
JavaScript
2
star
39

workshop-vue-2019-11-22

Vue
1
star
40

identify-element

A simple way to uniquely identify an HTML element.
JavaScript
1
star
41

workshop-till

JavaScript
1
star
42

workshop-testing

JavaScript
1
star
43

barcamp-hk-2016

Podklady k prednáške pre Barcamp Hradec Králové 2016
JavaScript
1
star
44

webinar-vue

Vue
1
star
45

config-mask

Helper that takes care of validating, sanitizing and coercing of complex config objects.
JavaScript
1
star
46

webinar-vue3

Vue
1
star
47

keyboard-visualiser

Sample project for JavaScript tools workshop
JavaScript
1
star
48

webinar-test-tools-js

JavaScript
1
star
49

expose

JavaScript helper for exposing objects to global namespace.
CoffeeScript
1
star
50

loger

Very simple loger for NodeJS.
JavaScript
1
star
51

carve

JavaScript
1
star
52

style-properties

JavaScript library for getting information about element style properties in unified and usable format.
JavaScript
1
star
53

2023-10-12-frontkon-typescript-bez-typescriptu

JavaScript
1
star
54

eslint-config

JavaScript
1
star
55

talk-2019-10-16-frontendisti

Podklady k prednáške na minikonferencii Frontendisti, 16.10.2019 v Slevomat.cz
Vue
1
star