Posts Tagged ‘Selectors API’

Introducing Jacqueline: unused CSS Selectors in Java

Monday, June 15th, 2009

Back in 2008 I wrote some articles about the proposed Selectors API for the DOM. Now, in 2009, it’s still “only” a working draft of the W3C. I’ve been exploring this topic for a long time, now I will finally have time to write about what I’ve been working on for several months.

Jacqueline is a library which will help you to find unused CSS Selectors in multiple HTML documents. This is a very important feature when you want to check a complete website: it will be almost certain that you have some CSS selectors used on page “A” but not on page “B” whereas “B” uses some CSS selectors which “A” doesn’t use.

Jacqueline is completely written in Java – this was necessary because we wanted to run it in our Java based infrastructure. This brings some other problems Jacqueline has to face: the DOM implementation in Java doesn’t feature the Selectors API. So I wrote a CSS-to-XPath engine – inspired by DOMAssistant. What this basically does is: it transforms CSS2.1 selectors into XPath queries which can then be used for node tests (since XPath support is included in the JDK) on the DOM tree of the HTML document.

Because our documents are still using HTML 4.0 (due to several problems when switching to XHTML 1.0) I had to use JTidy for building DOMs.

Jacqueline also uses Apache Batik to retrieve all the CSS rules and CSS selectors from a document – it was the only implementation of the SAC (Simple API for CSS) I got to run – and which had some special features. These include locator information of the found tokens for example.

At the moment Jacqueline only works single-threaded, but because this includes many cpu-intensive operations which could definitely be fastened by using the power of multiple cores I’m also dreaming of a multi-threaded version. Since most operations of Jacqueline could be executed in a parallel fashion this could bring a major speed-up.

The main thing of Jacqueline is that it’s one of the first pieces to the lately mentioned Project Mess Tool. We’ll be using the power of Jacqueline to detect unused CSS selectors in our web projects.

Finally, that stupid name: Jacqueline is named after Jacqueline Bouvier from my favorite TV show the Simpsons. See this poster in our office:

Jacqueline - Poster

Jacqueline - Poster

Weitere Entwicklungen

Saturday, October 11th, 2008

Leider hatte ich zuletzt nicht sonderlich viel Zeit um meine Entwicklungen z.B. bei meinem Selectors-Tool weiter voranzutreiben. Mein Studium an der Berufsakademie Mosbach (oder neu: “University of Cooperative Education”) ist leider sehr zeitintensiv. Außerdem werde ich meine Entwicklungen auf diesem Gebiet im nächsten Praxisblock bei 1&1 wieder weiterverfolgen – auch unter dem Gesichtspunkt einer zweiten Praxisarbeit.

Selectors API in Opera Acid3 Build

Thursday, August 14th, 2008

Kurzes Update:

Auch bei Opera bemüht man sich natürlich die neuen Web Standards zu unterstützen und so gibt es seit Ende März ein Build das eine 100/100-Completion im Acid3-Test erfüllen soll (näheres im Entwicklerblog).

In diesem Build ist auch eine native Implementierung des Selectors API eingebaut. Die mit dem von mir aufgebauten Test-Szenario Ergebnisse zwischen 16 und 32ms erzielt.

Diese Werte lassen sich leider nicht 1:1 mit den anderen ermittelten vergleichen, da sie in unterschiedlichen Test-Umgebungen (Core2Duo 1.8 statt Core2Duo 2.6 – Windows XP statt Mac OS X) entstanden sind.

Firefox 3.1a testet Selectors API

Saturday, August 9th, 2008

Laut John Resig wird in Firefox 3.1 mit der nächsten Gecko-Version ebenfalls eine native Unterstützung für das Selectors API eingebaut sein. Ich habe mir eine Nightly-Version von Firefox 3.1 (Minefield 3.1a2pre) für Mac OSX geholt und sie über meinen kleinen Test-Parcour geschickt. Die Ergebnisse sprechen für sich. Im Vergleich zur Javascript-Implementierung via Base2.DOM zeigt sich hier ein Bild ähnlich dem in Safari 3.1:

  • beim Test mit querySelectorAll fällt die Zeit von 235ms im Mittel auf 25ms
  • bei querySelector sind es nun 17ms statt vorher 151ms

Damit erreicht Firefox 3.1a zwar nicht ganz die bisherigen Spitzenwerte von Safari 3.1 (11ms/8ms) holt aber mächtig auf.

Auch bei Opera schläft man nicht und so gibt es seit Ende März ein Acid3 build von Opera das ebenfalls eine native Implementierung des Selectors API besitzt. Auch dafür werde ich die Performance testen, sobald ich dazu komme.

Gleichzeitig arbeite ich an einer neuen Version des Benchmarks um alltagstaugliche Testergebnisse zu erbringen. Die Arbeit an meinem eigenen kleinen Tool zur Nutzung des Selectors API steht momentan ein bischen hinten an.

Selectors API in Firefox 3.1

Tuesday, July 29th, 2008

Ich war erfreut zu lesen, dass Firefox 3.1 mit Gecko 1.9.1 nun ebenfalls das Selectors API unterstützen wird.

Gleichzeitig ist mir ein Artikel von John Resig vom 10. Juli aufgefallen, der sich ebenfalls mit einer Test Suite für das Selectors API beschäftigt. Im Gegensatz zu den Performance-Tests werden in dieser Test Suite die einzelnen Implementierungen auf ihre Vollständigkeit der Selektoren hin überprüft. Mir waren bei Webkit/Safari schon Fehler bei etwas “exotischeren” Selektoren aufgefallen, was sich hiermit bestätigt hat. Die Implementierung Firefox 3.1 hingegen deckt laut Artikel schon weite Teile (ca. 70%) der Selektoren ab.

Ich werde mir in den nächsten Tagen eine Alpha-Version von Firefox 3.1 besorgen und hier ebenfalls die Performance testen.